
hi friends,
i am trying a java API using HTTPCLient post method. in which i am getting output having some authentication problem. can any one please help me to solve this problem.
please , please help me.. waiting for reply.
Thanks in advance.
//--------------------------------
This is what the PROGRAM------------
import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*;
public class sms {
public static void main( String[] args ) throws Exception {
String qURL="http://9.184.65.219:10038";
String UserId="adm";
String Password="adm";
String postTitle="Pls11";
byte entry[] = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"> <title type=\"text\"> "+postTitle+" </title></entry>").getBytes();
String placeurl = qURL+"/asd/myquic"+"/feed";
try { System.out.println("\n Place Collection URL = "+ placeurl);
HttpClient client = new HttpClient();
PostMethod method = new PostMethod( placeurl );
// Configure the form parameters
method.addParameter( "CONTENT-TYPE", "application/atom+xml" ); method.addParameter( "CONTENT-LENGTH", new Integer(entry.length).toString() ); method.addParameter( "Host", "localhost"); method.addParameter( "User-Agent", "Thingio/1.0" ); method.addParameter( "Keep-Alive", "header"); method.addParameter( "Authorization", "Basic " + (new sun.misc.BASE64Encoder().encode((UserId+":"+Password).getBytes())));
System.out.write(entry);
// Execute the POST method
int statusCode = client.executeMethod( method );
System.out.println("\n Response status code: " + statusCode);
// Display response
System.out.println("\n Response body: ");
System.out.println(method.getResponseBodyAsString());
}
catch( Exception e ) { System.err.println ( "\n Exception...\n" + e ) ; e.printStackTrace(); } }
output
Place Collection URL = http://9.184.65.219:10038/asd/myquic/feed
Response status code: 401
Response body:
//-----------------
Thanks and regards, Milind........
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.