I should send within an http post request (inside the request body) an xml string formatted like the following:
<message>
<man>
<age>18</age>
<sex>m</sex>
</man>
<result>
<math>8</math>
<science>8</science>
</result>
</message>
The POST requests should have a Content-Type header set to "text/xml; charset=UTF-8".
How can i do this? i din't get how httppost works for jsp...heeelp! :)
Answer to this should be this:
http://amitkgaur.blogspot.it/2009/12/post-xml-data-without-form-in-jsp-and.html
Related
I am trying to create soap request in android but not able to get how to generate this.
I have gone through following URL:-
url-1
url-2
but not able to understand how to create soap request like this.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stal="http://ws.soapwebserv.com/Info">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis- open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-30" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>alias101#soapwebserv.com</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">somesecurepassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<stal:InfoRequest>
<token>randomtokenrandomtoken</token>
</stal:InfoRequest>
</soapenv:Body>
</soapenv:Envelope>
please help me out guys... I am new to Soap. :(
simple way is to copy the entire soapenvelope in raw folder as xml file and pass your username ,password and token with help of pattern matching . Now you have the entire request in the form of string pass the request to httppost method.let me know that helps your issue.
So I'm trying to connect to a REST server with HTTPURLConnection. The HTTPGET request needs to be of content-type application/json. When I use setRequestProperty("Content-Type", "application/json"); the value is overriden to "text/html" but when I use setRequestProperty("Accept", "application/json"); the Content-Type is set to application/json. Why can't I use Content-Type when specifying? Clarification is greatly appreciated.
My current guess is that "Accept" works with HTTPGET and "Content-Type" is for HTTPPOST.
More code:
connection.setRequestMethod("GET");
connection.setUseCaches(false);
//connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
AFAIK, the Content-Type header in an HTTP request would be for the type of content being sent as the body, and is used on requests like POST and PUT. Accept is the header that indicates what MIME types the requester would like to receive in a response.
I am trying to connect to apache tomcat server using HTTP POST, when i see LOG file of server it showing GET /login/validate_doc.jsp HTTP/1.1" 200 685 ,
which means it is getting a GET request when i am sending using HttpPost and form parameters are not received by server.
my code is below:
HttpPost post_http=null;
post_http=new HttpPost("http://somexx.ac.in/medONmob/validate_doc.jsp");
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username",username));
nameValuePairs.add(new BasicNameValuePair("password",password));
post_http.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Where am i wrong ...??? Help me out please
Try specifying encoding when constructing UrlEncodedFormEntity. By default it is ISO-8859-1.
Also this will make your code future safe
Creating a UrlEncodedFormEntity from a List of NameValuePairs throws a NullPointerException
Given that you are using a post, then you probably are sending data on your request body, Am I right?, then you have to specify the content-type of the data you are sending in the headers, in order to execute a proper post:). For example if I am sending a json in the request body then I should add a header like this:
request.addHeader("content-type", "text/json");
Cheers
My authorization header is "Authorization: TRUEREST username=user &password=pass&apikey=key&class=class". How to put it into HTTPPOST request..?
I am doing it like :
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Authorization","TRUEREST");
httppost.setHeader("username","user");
httppost.setHeader("password","pass");
httppost.setHeader("apikey","key");
httppost.setHeader("class","class");
Credentials don't get send. What is wrong in this code??
Kindly help..!!
Thanks in advance.
First, are you sure you need to put all of those in the 'Authorization' header? Second what you are doing is adding 5 different headers with each value, not adding a single 'Authorization' header.
The '&' usually means you need to send those values as POST/GET parameters, but do check your specs.
I want to access a Restful web service. I want the request should be in the following format.
GET /API/Contacts/username HTTP/1.1
HOST: $baseuri:port
Accept: text/xml
Authorization: Basic ZmF0aWdhYmxlIGdlbmVyYXR=
And also I am calling the web service though HTTPS protocol.
The folowing is the code I am using :
HttpGet get = new HttpGet("https://secure.myapp.com/MyApp/API/Contacts/myname");
get.addHeader("Accept","text/xml");
get.addHeader("Authorization","Basic ZmF0aWdhYmxlIGdlbmVyYXR=");
get.addHeader("Host","https://secure.myapp.com");
get.addHeader("Connection Use","HTTP 1.1");
DefaultHttpClient client = new DefaultHttpClient();
ResponseHandler objHandler = new BasicResponseHandler();
String getResponse = client.execute(get,objHandler);
But I am getting an Error : 400 Bad request.
I am not sure whether my code is correct. Is it necessary to specify the method (GET, POST or PUT) explicitly in the header?
Please help me...
Thnking You....
Shouldn't you put 'Basic ZmF0aWdhYmxlIGdlbmVyYXR=' in double quotes?
Also check web service example request and response and make sure that everything is specified.
Ohh...
That was my mistake.
I did not keep the order of adding headers.
When I changed its order according to the Request it is working fine.
In the request the HOST should be the first parameter.
The following is the corrected code.
get.addHeader("Host","secure.myapp.com");
get.addHeader("Accept","text/xml");
get.addHeader("Authorization","Basic ZmF0aWdhYmxlIGdlbmVyYXR=");
get.addHeader("Connection Use","HTTP 1.1");
Sorry to disturb you all...