File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Posting values to HTTPS Url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Posting values to HTTPS Url" Watch "Posting values to HTTPS Url" New topic
Author

Posting values to HTTPS Url

nishad km
Greenhorn

Joined: Oct 14, 2004
Posts: 7
hi All,

From my applicaiton we need to access an external url for mail servcice.we will have to establish the connection with this server and POST the values to this server. The external Server URL is in HTTPS, and requires a basic authentication.

the code is given below. I am getting error :java.net.ConnectException: Tried all: 1 addresses, but could not connect over HTTPS to server: "domainname" port: 443

java.net.URL url = new URL("https:\\domainname\...\index.php");
HttpsURLConnection connection = new HttpsURLConnection(url);
String userNamePassword="username assword";
String encoding= new BASE64Encoder().encodeBuffer userNamePassword.getBytes());
connection.setRequestProperty("Authorization","Basic "+encoding);
connection.setTimeout(wom_connection_timeout);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoOutput(true);

Can any body suggest a way to connect to a Server through https url and pass the post variables?

thanks,
Nishad

[ October 30, 2008: Message edited by: nishad km ]
[ October 30, 2008: Message edited by: nishad km ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
You aren't really using "domainname" as the server name, are you?

Is the server reachable by HTTP from the machine this code runs on?


Ping & DNS - my free Android networking tools app
nishad km
Greenhorn

Joined: Oct 14, 2004
Posts: 7
i am able to connect to that Url through browser( https- http will not work)but through application i was not able to.

Can you tell me how to post the values? is it same as the urlparameter like
&name=nishad&action=queue.. Or we need to ecrypt the values
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Can you connect to any other server by HTTPS using code similar to that?
nishad km
Greenhorn

Joined: Oct 14, 2004
Posts: 7
Ya i am not able to connect any https urls, as the request goes through our proxy server and in proxy server https is not enabled. thanks for the help.

But can you tell me username and password for authentication should be in encrypted format or not when post the request? if we send the other values as query string(name=nishad) will it be fine?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
But can you tell me username and password for authentication should be in encrypted format or not when post the request?

The username/password stuff looks OK as it is. A good test for this is to try it with an HTTP URL instead of an HTTPS URL.

if we send the other values as query string(name=nishad) will it be fine?

That depends on the server-side. There's nothing like a bit of trial-and-error :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Posting values to HTTPS Url