java - org.apache.http.client.ClientProtocolException in HttpPost -
I try to upload some strings on the server. When I try to upload to the server, in the string:
HTTPRSpace response = httpclient.execute (httppost); I have the error org.apache.http.client.ClientProtocolException I have all the code:
public zero-transmitted string (string string tossed) {try {DefaultHttpClient Httpclient = new DefaultHttpClient (); Httpclient.getCredentialsProvider () Set credentials (AuthScope.ANY, new username password credentials (username, password)); Http post httppost = new HTTP post (server address); InputStreamEntity reqEntity = New InputStreamEntity (new bytereinputstream (stringToSend.getBytes ()), stringToSend.length ()); ReqEntity.setContentType ("application / xml"); Httppost.setEntity (reqEntity); HttpResponse response = httpclient.execute (httppost); If (response.getStatusLine (). GetStatusCode ()! = Org.apache.http.HttpStatus.SC_OK) {Log.i ("Send", "Do not Send" + Feedback .getStatusLine ()); } Else {Log.i ("SEND", "Send OK") + feedback .getStatusLine ()); }} Hold (IOException e) {Log.w ("IOException", e.toString () + "" + e.getMessage ()); }}
this should work
public Zero SendString (string string tossed) {try {HttpParams httpParams = new BasicHttpParams ()); DefaultHttpClient httpclient = New DefaultHttpClient (httpParams); Httpclient.getCredentialsProvider () Set credentials (AuthScope.ANY, new username password credentials (username, password)); Http post httppost = new HTTP post (server address); InputStreamEntity reqEntity = New InputStreamEntity (new bytereinputstream (stringToSend.getBytes ()), stringToSend.length ()); ReqEntity.setContentType ("application / xml"); Httppost.setEntity (reqEntity); HttpResponse response = httpclient.execute (httppost); If (response.getStatusLine (). GetStatusCode ()! = Org.apache.http.HttpStatus.SC_OK) {Log.i ("Send", "Do not Send" + Feedback .getStatusLine ()); } Else {Log.i ("SEND", "Send OK") + feedback .getStatusLine ()); }} Hold (IOException e) {Log.w ("IOException", e.toString () + "" + e.getMessage ()); } }
Comments
Post a Comment