Android soap request posting -sample? - android

I want to send the SOAP xml request to php server from android device, as shown below are required parameter for posting request. Currently i am not getting any method or sample to do achieve.Any suggest some samples.
POST /sample/server.php HTTP/1.0
Host: x.x.x.x
User-Agent: NuSOAP/0.7.3 (1.114)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: ""
Content-Length: 551
Thanks

Related

How to get Android volley request header?

I am trying to get the request headers sent to server from Android volley request.
I can find webView headers as below
Host: www.example.com
Connection: keep-alive
Accept: image/webp,image/*,*/*;q=0.8
User-Agent: Mozilla/5.0 (Linux; Android 5.0.2 ...
X-re ...
But I can't find the volley request header structure to be manipulated by web server. Please help.
I can't find nothing from
VolleyRequest.getHeaders() //output => {}

HTTP POST RETURNING BAD REQUEST ERROR 400 FROM ANDROID HTTPURLConnection

I am using the HTTPURLConnection class to connect my android application to my WCF web service. I am using Microsoft Network Monitor to trace the request and it hits my server as thus.
Http: Request, POST /iEService/Service.svc/register_user
Command: POST
URI: /iEService/Service.svc/register_user
Location: /iEService/Service.svc/register_user
ProtocolVersion: HTTP/1.1
UserAgent: Dalvik/2.1.0 (Linux; U; Android 5.0.2; A0001 Build/LRX22G)
Host: win-server
Connection: Keep-Alive
Accept-Encoding: gzip
ContentType: application/x-www-form-urlencoded
MediaType: application/x-www-form-urlencoded
ContentLength: 183
HeaderEnd: CRLF
payload: HttpContentType = application/x-www-form-urlencoded
Last_Name: l_one
Birthday: bd_one
Email: e_one
Username: u_one
Business_Location: bl_one
Security_Answer: sa_one
Security_Question: s_one
First_Name: f_one
Password: p_one
IMEI_Number: imei_one
However, I get a Bad Request error 400. I cannot see anything wrong with the request. What could be the problem?
The problem was in my WCF service method. All i had to do was add
BodyStyle:=WebMessageBodyStyle.WrappedRequest
to the method header.
And it worked.

Mailgun POST /messages API always throw 401 forbidden

I am trying to send Mailgun POST /messages API request in Android using retrofit library.
Following is retrofit request:
HTTP POST https://api:key-xxx/v3/sandboxxxx/messages
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
Content-Length: 148
from=Excited+User+%3Cmailgun%40sandboxxxxmailgun.org%3E&to=vir.jain%40gmail.com&subject=Hello&text=Testing+awesomeness
Response:
HTTP 401 https://api:key-xxx/v3/sandboxxxx.mailgun.org/messages (1966ms)
Server: nginx/1.7.9
Date: Mon, 15 Jun 2015 10:00:37 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 9
Connection: keep-alive
WWW-Authenticate: Basic realm="MG API"
OkHttp-Selected-Protocol: http/1.1
OkHttp-Sent-Millis: 1434362440805
OkHttp-Received-Millis: 1434362441086
Forbidden
When I try this same request on Postman, it works perfectly & email is sent properly. But when sending using retrofit library from Android fails with Forbidden.
My Retrofit API:
#FormUrlEncoded
#POST("/messages")
public void sendEmail(#Field("from") String from, #Field("to") String to, #Field("subject") String subject, #Field("text") String text, RestCallback objectRestCallback);
Base URL is:
https://api:key-xxx/v3/sandboxxxsandboxxxx.mailgun.org
Everything is form URL encoded. But I'm really not sure what going wrong.
Can anyone please help me out whats wrong with above API?
Thank you,
Mahavir
I added following authorization header with Base64 encoded string of API key to the request, it started working.
request.addHeader("Authorization", "Basic "+getBase64String("api:key-xxxYOUR-API-KEY>"));
#Selvin: Thanks so much for sending wiki link :).
you need to specify your mailgun region: mg.SetAPIBase(mailgun.APIBaseEU)
// Create an instance of the Mailgun Client
mg := mailgun.NewMailgun(yourDomain, privateAPIKey)
mg.SetAPIBase(mailgun.APIBaseEU)

Authlogic and Android, Verify user credentials

I have a rails app that uses Authlogic (from gem Communityengine). Now I want users to be able to login on a mobile device (Android in that case)
If I understand correctly I can use Http Basic Authentication to authorize specified actions, but the first step (I think) is, when the user enters his username and password in his Android device, to check wether that user exists and if that passwort is correct.
How would I do this?
The password is encrypted in the database (with a pw salt) So as I understand I can not just check the database if the provided user and password is correct.
Here are some Http headers from my app as the result from different curl requests I did, I guess Http basic auth is working since I get a correct HTTP code when I provide user credentials:
martin#martin-desktop:~/Applications$ curl -I username:password#localhost:3000/users/username/posts/new
HTTP/1.1 200 OK
Date: Sun, 21 Apr 2013 12:17:29 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.19
X-UA-Compatible: IE=Edge,chrome=1
ETag: "b9aa82940f06722b7d8e35ce46e3166d"
Cache-Control: must-revalidate, private, max-age=0
X-Request-Id: 291ee45de8cb95e06ed4e8e6d3d9408c
X-Runtime: 0.335820
X-Rack-Cache: miss
Set-Cookie: _AppName_session=BAh7CkkiD3Nlc3Npb25faWQGOgZFRkkiJTA0ZDRhYmQwNDJjYmM1OGJmZTkyNzJjMTc5NThkODg0BjsAVEkiDnJldHVybl90bwY7AEZJIj1odHRwOi8vZ2l2LWR1ZXJlbi51bmktbXVlbnN0ZXIuZGUvdXNlcnMvbWFydGluL3Bvc3RzL25ldwY7AEZJIhV1c2VyX2NyZWRlbnRpYWxzBjsARkkiAYAzYWM2NTJlMjgyODA5MTY1ODg2ZTBjNTdhNGUzYjk5MzRkNWQ0YTE4MDdlN2M0MWI2OTQzYmQyNzZmOGFlMGI5NjliMjU3NzZhYTg4NjBkM2U0Y2Q5YTJjYzgwODVlNzY5NDgwMzE2MmQ3NTBjYzlhMmQ4ZTViYTJmNjJmYzVhZQY7AFRJIhh1c2VyX2NyZWRlbnRpYWxzX2lkBjsARmkGSSIQX2NzcmZfdG9rZW4GOwBGSSIxYzlIQitJNXNYZHNGa2NCb2hKcm5DY2tIcHNxdWJuWDEydVdZUU5WSlMvZz0GOwBG--2b5f5687425d7ec414e34b79eb89e0b6b465c86f; path=/; HttpOnly
Status: 200
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
martin#martin-desktop:~/Applications$ curl -I localhost:3000/users/username/posts/new
HTTP/1.1 302 Found
Date: Sun, 21 Apr 2013 12:17:40 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.19
X-UA-Compatible: IE=Edge,chrome=1
Cache-Control: no-cache
X-Request-Id: 9e4b9094f99f5877c8fb79647a1a22f1
X-Runtime: 0.004657
X-Rack-Cache: miss
Set-Cookie: _AppName_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWJhZGVlNzBjNjA0YmQ1MTgyYmI5OWMxZjcxOGIzZmZkBjsAVEkiDnJldHVybl90bwY7AEZJIj1odHRwOi8vZ2l2LWR1ZXJlbi51bmktbXVlbnN0ZXIuZGUvdXNlcnMvbWFydGluL3Bvc3RzL25ldwY7AEY%3D--32120aefd22c0748c352b016582451ede84225ca; path=/; HttpOnly
Location: localhost:3000/login
Status: 302
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
What I also found out so far is, that the Set-Cookie uses Base64 encoding (This is the encoding for the resulting string literal from http basic auth)
Any help is appreciated!
Nevermind I added this method, which checks for username and password validity and writes the result in the header:
def auth
authenticate_or_request_with_http_basic do |username, password|
if user = User.find_by_login(username)
response.headers['Auth'] = 'Password incorrect'
if user.valid_password?(password)
response.headers['Auth'] = 'Credentials correct'
end
else
response.headers['Auth'] = 'Username incorrect'
false
end
end
end
In my mobile application I just send a request to username:password#mysite.com and read the http header. Not sure if this is an elegant method or if it is inteded, but it works for now.

How to send XML data via HTTP POST with Android

i am developing an Android client to do the following HTTPRequest and read the response. i created the back end and tested with a web service tester tool. this snippet was taken by that tool. since Android has limited support for SOAP i am looking for a way of doing this with HTTP POST. can anybody tell me a way to do this.
POST /demo/internalsoapgateway HTTP/1.1
Host: myIP:PORT
Content-Type: text/xml; charset=UTF-8
InteractiveMode: false
Authorization: Basic aWZzYXBwOmlmc2FwcA==
Accept-Language: en-US
SOAPAction: urn:soap_access_provider:BrowseCountry:QueryTrnCountry
User-Agent: Java/1.5.0_11
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 381
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TRN_COUNTRY_QUERY xmlns="urn:ifsworld-com:schemas:browse_country_query_trn_country_request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</TRN_COUNTRY_QUERY>
</soap:Body>
</soap:Envelope>
Thank You !!
See this question: Sending pictures to a web server

Categories

Resources