我正在开发一个应用程序,并希望使用HttpPut请求发送内容。 我发送它但它无法识别远程服务器。 我将请求发送到REST API。
这是我的代码:
HttpURLConnection connection;
try{
URL url = new URL(Constants.url_domain+"listings/"+idvalue);
//URL url = new URL(imageUrl);
HttpPut httpRequest = null;
httpRequest = new HttpPut(url.toURI());
String basicAuth = "Basic " + new String(Base64.encode("username:password123#".getBytes(),Base64.NO_WRAP ));
httpRequest.setHeader("Authorization", basicAuth);
MultipartEntity entity2 = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity2.addPart("title",new StringBody(titlevalue));
entity2.addPart("price",new StringBody(pricevalue));
entity2.addPart("active",new StringBody("false"));
httpRequest.setEntity(entity2);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
}