Results 1 to 1 of 1
Thread: POST Data to SSL Endpoint
- 08-15-2011, 06:07 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 2
- Rep Power
- 0
POST Data to SSL Endpoint
I'm having a little difficult posting a set of data to an HTTPS endpoint. This is what I have so far:
The error i'm receiving is:Java Code:public String postData(String content, String access_token){ try{ String data = URLEncoder.encode("body", "UTF-8") + "=" + URLEncoder.encode(content, "UTF-8"); data += "&" + URLEncoder.encode("access_token", "UTF-8") + "=" + URLEncoder.encode(access_token, "UTF-8"); // Create a socket to the host String hostname = "the.domain.com"; int port = 443; SocketFactory socketFactory = SSLSocketFactory.getDefault(); Socket socket = socketFactory.createSocket(hostname, port); // Send header String path = "/path-to-endpoint"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8")); wr.write("POST "+path+" \r\n"); wr.write("Content-Length: "+data.length()+"\r\n"); wr.write("Content-Type: application/x-www-form-urlencoded\r\n"); wr.write("\r\n"); // Send data wr.write(data); wr.flush(); // Get response BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream())); String output = ""; String line; while ((line = rd.readLine()) != null) { output += line; } wr.close(); rd.close(); return output; } catch (Exception e) { System.out.println(e); } return ""; }
I'd appreciate any suggestions on what i'm doing wrong or on better approaches to this problem.java.net.SocketException: Software caused connection abort: socket write error
Thanks.
Similar Threads
-
drawLine - inconsistent endpoint
By buffalo in forum Advanced JavaReplies: 5Last Post: 04-27-2011, 01:43 AM -
Formatting POST data with a pkcs#7 signature
By abhijitdutta82 in forum Advanced JavaReplies: 0Last Post: 12-22-2010, 07:21 AM -
javax.xml.ws.Endpoint how to restart
By Rickyp in forum Advanced JavaReplies: 0Last Post: 11-30-2010, 11:32 AM -
how to post data to a website using java
By mr_anderson in forum Advanced JavaReplies: 6Last Post: 11-12-2010, 11:46 AM -
how to POST data to server using HttpURLConnection ??
By dhana in forum NetworkingReplies: 4Last Post: 10-15-2008, 01:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks