我想将txt文件上传到网站,我承认我没有对其进行任何详细的研究,但是我看了一些示例,并希望就我是否朝着正确的方向提出更多的经验性意见. .
这是我到目前为止的内容:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
private String ret;
HttpResponse response = null;
HttpPost httpPost = null;
public String postPage(String url,String data,boolean returnAddr) {
ret = null;
httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.RFC_2109);
httpPost = new HttpPost(url);
response = null;
StringEntity tmp = null;
try {
tmp = new StringEntity(data,"UTF-8");
} catch (UnsupportedEncodingException e) {
System.out.println("HTTPHelp : UnsupportedEncodingException : "+e);
}
httpPost.setEntity(tmp);
try {
response = httpClient.execute(httpPost,localContext);
} catch (ClientProtocolException e) {
System.out.println("HTTPHelp : ClientProtocolException : "+e);
} catch (IOException e) {
System.out.println("HTTPHelp : IOException : "+e);
}
ret = response.getStatusLine().toString();
return ret;
}
我称之为:
postPage("http://www.testwebsite.com","data/data/com.testxmlpost.xml/files/logging.txt",true));
但是当以这种方式尝试时,我得到以下响应.
HTTP/1.1 405 Method Not Allowed
我是在尝试正确的方法还是应该以其他方式进行操作?
最佳答案
原文链接:https://www.f2er.com/android/531517.html