Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

http Client Authentication

Ads

 
 

Share on Google+Share on Google+

milind
http Client Authentication
0 Answer(s)      6 years and 7 months ago
Posted in : Java Beginners
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
<?xml version="1.0" encoding="UTF-8"?><entry xmlns="http://www.w3.org/2005/Atom">
Pls11 Jan 10, 2011 3:17:19 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: basic authentication scheme selected
Jan 10, 2011 3:17:19 PM org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallenge
INFO: No credentials available for BASIC [email protected]:10038

Response status code: 401

Response body: 
Thanks and regards,
Milind.
Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
http Client Authentication
http Client Authentication  hi friends, i am trying a java API... authentication problem. can any one please help me to solve this problem. please... ) throws Exception { String qURL="http://9.184.65.219:10038"; String
Spring Security HTTP basic authentication
Spring Security HTTP basic authentication In this section, you will learn about the HTTP basic authentication in Spring Security. You can configure HTTP... Security HTTP basic authentication configuration--> <http> <intercept
Advertisements
Version of com.cognitect>http-client dependency
List of Version of com.cognitect>http-client dependency
Version of com.jslsolucoes>http-client dependency
List of Version of com.jslsolucoes>http-client dependency
Version of com.metamx>http-client dependency
List of Version of com.metamx>http-client dependency
Version of com.rabbitmq>http-client dependency
List of Version of com.rabbitmq>http-client dependency
Basic authentication
the client's built in authentication mechanism. In java programming language... Basic authentication       Basic authentication is the process through which a web server authenticates
Version of com.agapsys>simple-http-client dependency
List of Version of com.agapsys>simple-http-client dependency
Version of com.dslplatform>dsl-client-http dependency
List of Version of com.dslplatform>dsl-client-http dependency
Version of com.gooddata>gooddata-http-client dependency
List of Version of com.gooddata>gooddata-http-client dependency
Version of com.nycjv321>simple-http-client dependency
List of Version of com.nycjv321>simple-http-client dependency
Version of com.sendgrid>java-http-client dependency
List of Version of com.sendgrid>java-http-client dependency
Maven Dependency http-client >> 0.1.71
You should include the dependency code given in this page to add Maven Dependency of com.cognitect >> http-client version0.1.71 in your project
Maven Dependency http-client >> 0.1.73
You should include the dependency code given in this page to add Maven Dependency of com.cognitect >> http-client version0.1.73 in your project
Maven Dependency http-client >> 1.1.0.RELEASE
You should include the dependency code given in this page to add Maven Dependency of com.rabbitmq >> http-client version1.1.0.RELEASE in your project
Maven Dependency http-client >> 1.1.1.RELEASE
You should include the dependency code given in this page to add Maven Dependency of com.rabbitmq >> http-client version1.1.1.RELEASE in your project
Maven Dependency http-client >> 0.1.62
You should include the dependency code given in this page to add Maven Dependency of com.cognitect >> http-client version0.1.62 in your project
Maven Dependency http-client >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.jslsolucoes >> http-client version1.0.0 in your project
Maven Dependency http-client >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.metamx >> http-client version1.0.0 in your project
Maven Dependency http-client >> 1.0.0.RELEASE
You should include the dependency code given in this page to add Maven Dependency of com.rabbitmq >> http-client version1.0.0.RELEASE in your project
Maven Dependency http-client >> 1.2.0.RELEASE
You should include the dependency code given in this page to add Maven Dependency of com.rabbitmq >> http-client version1.2.0.RELEASE in your project
Version of com.dslplatform>dsl-client-http-android dependency
List of Version of com.dslplatform>dsl-client-http-android dependency
Version of com.dslplatform>dsl-client-http-apache dependency
List of Version of com.dslplatform>dsl-client-http-apache dependency
Version of com.despegar>http-java-native-client dependency
List of Version of com.despegar>http-java-native-client dependency
java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient  Hi, I have a program which is developed using the http client. It is giving following error: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
How to fireup HTTP request from JavaFX Client
How to fireup HTTP request from JavaFX Client  Please tel me how do I can fire HTTP post request from an JavaFX client. Sceneario: I've an JavaFX... i've working version of JSP Code to handle HTTP post request tested by posting
Authentication - JavaMail
Authentication program in Java  How to write a program in Java for user authentication
Authentication in Servlets
Authentication in Servlets  What are different Authentication options available in Servlets
noclassdeffounderror: org/apache/http/client/methods/httpurirequest
noclassdeffounderror: org/apache/http/client/methods/httpurirequest  Hi, One of my application is throwing following error: noclassdeffounderror: org/apache/http/client/methods/httpurirequest How to resolve this? Thanks  
Maven Dependency simple-http-client >> 0.1.0-20170322
You should include the dependency code given in this page to add Maven Dependency of com.agapsys >> simple-http-client version0.1.0-20170322 in your project
Maven Dependency dsl-client-http >> 0.4.13
You should include the dependency code given in this page to add Maven Dependency of com.dslplatform >> dsl-client-http version0.4.13 in your project