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
Related
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)
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.
Using the ksoap2 library (v2.6.4), SOAP version11, I'm executing a web service via a 2.3.3 emulator device. The server recognizes the requested action and provides the expected answer. The HTTP/1.1 header (debugged at the server side) contains the following:
User-Agent: ksoap2-android/2.6.0+
SOAPAction: myAction
Content-Type: text/xml;charset=utf-8
Connection: close
Content-Length: 1481
Host: xxx.xxx.xxx.xxx
Accept-Encoding: gzip
Trying to fire up the same application - everything is the same (if there's such a thing in the IT world), same source, library, soap config, request, server etc. - but this time on a 2.2 emulator device. The server rejects the request claiming that the SOAPAction is missing from the request. Logs show that this request came with the following HTTP header:
user-agent: ksoap2-android/2.6.0+
soapaction: myAction
content-type: text/xml;charset=utf-8
connection: close
content-length: 1481
Host: xxx.xxx.xxx.xxx
So the SOAPAction (among other parts of the header) arrives as a lowercase parameter. The server does not recognize the lowercase "soapaction" and rejects my request. I'd need this application to work on Android 2.2+
Any ideas where to start?
EDIT: This is how I send my SOAP request. If that's any help.
public Object executeMyFunction(SoapObject request) throws Exception {
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.implicitTypes = false;
envelope.dotNet = true;
envelope.setAddAdornments(false);
HttpTransportSE _ht = new HttpTransportSE(Configuration.getWsUrl());
_ht.call("myFunction", envelope);
return envelope.getResponse();
}
I had similar problem with ksoap2. Application was working on android version 2.2 but not on 2.3.3. That thing that cause problem was caseing, so I was looking for response header parameter :
set-cookie
insted of
Set-Cookie
IgnoreCase solved my problem. You should allways try to catch http messages from emulator with wireshark, and than compare them.
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
We have a website that makes use of OAM for single sign on (form-based authentication). When we submit credentials to WebGate / Access Server the authorization succeeds, however after the authentication is performed, the form action (as configured in the Authentication Scheme - with passthrough:no) returns a server error instead of redirecting to the originally requested URL.
If we use Mini Opera, we are able to get authenticated and forwarded properly.
This problem happens on numerous Android phones (versions ranging from 1.5-2.2), as well as the Emulator provided with the SDK.
This is proving to be a real problem as the default browser on Android phones is not able to get access to our sites(and this is the only browser that is having this problem).
I have created a WebView-based custom browser with the hope of seeing a client-side error and tried trapping every possible error....none show up....
I have tried to trace all of the http requests and found only a single difference in the requests... the http header for Connection:keep-alive is not sent by the Android WebView.
I have provided some tracing info below...
Has anyone run into this problem? Has anyone solved this?
Any insight to this issue would be greatly appreciated.
Thanks,
Tim
Request RAW Data-
POST
http: // MYSERVER/security/ATLAFunction HTTP/1.1 Host: MYSERVER:7777
Accept-Encoding: gzip
Accept-Language: en-US
Cookie:ObSSOCookie=loggedoutcontinue
Accept-Charset: utf-8, iso-8859-1,utf-16, ;q=0.7
Referer:http://10.84.32.71:7777/tpf/login.html
User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; sdk Build/FRF42) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Origin: http: // MYSERVER
Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/*;q=0.5
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
uname=auser&pwd=appas
Raw Response Data -
HTTP/1.1 503 Service Temporarily
Unavailable Date: Tue, 05 Oct
2010 14:26:12 GMT Set-Cookie:
ObSSOCookie=II%2F4n5pFreT6B6hOAumv6pI6CZh6l04VhyXHrCzuRUT5hDEHMK%2FJCX659uyCkxgIyJ8ywB3BKrHxorsCwZwivpn91t9Mu%2FCKT7PrY23S518xoBeOam26tr%2B0pSfCbo%2FZXLmFIxjHFOPHPGxi5tHrOlUroXXA9Fe0GZz3SbJLMgAkCw0euuAVewOHKIjoDh8MwAdGtL4lo%2BmHhk5kB316iFJ4Aljr7cQYpAp1r%2BVGD9FbLkYl4ekY5hrlNfwYS%2BVjnR0uSIFjc0toiKkGN33z7%2FiElh2Ue2iWQrpCRcgFpxE%3D;
httponly; path=/; Cache-Control:
no-cache Pragma: no-cache
Content-Length: 312 Connection:
close Content-Type: text/html;
charset=iso-8859-1
<!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>503 Service Temporarily
Unavailable</title>
</head><body>
<h1>Service Temporarily
Unavailable</h1>
<p>Sorry!The server is
currently unable to handle the
request due to a temporary
overloading or maintenance of the
server.</p>
</body></html>