我有两个来自Android相机服务的字节[]数组。我想把它们和一些参数发布到我的AppEngine服务器上,运行pythonwebapp框架。在
问题:我一直在服务器端获取空的HTTP请求参数。在
我的主要方法是Apache HttpClient:
1)android2.x不包括MultiPartEntity类,这是multipart w/binary所必需的。所以我在构建路径中添加了httpime-4.0.1.jar和apache-mime4j-0.6.1.jar。在
2)安卓方面,我是这样做的:
public String post(String URI, byte[] jpeg, String description) {
// Setup MultiPartEntity
MultipartEntity args = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
args.addPart("mydescription", new StringBody(description));
// Now add the file
InputStream s1 = new ByteArrayInputStream(jpeg);
args.addPart("myfile", new InputStreamBody(s1, "image/jpeg", "1.jpeg"));
HttpClient httpclient = new DefaultHttpClient();
// HTTP 1.1 is much faster with HttpClient, same issues w/o it
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httpost = new HttpPost(URI);
httpost.setEntity(args);
HttpResponse response = httpclient.execute(httpost);
// blah blah blah, process response
}
3)Python AppEngine端,我的处理程序如下:
^{pr2}$4)参数为空->;空数组将打印到日志中。webob的低层self.request._request__body()
也是空的。坏兆头!在
5)如果不将InputStreamBody添加到MultipartEntity(只有StringBody参数),则一切正常,mydescription参数就会出现。
6)我设置了一个PHP服务器,并尝试发布:帖子与PHP一起工作!
7)HttpClient发送的格式导致webapp/webob/wsgi/cgi.FieldStorage公司或者有什么问题。我想不出它在哪儿坏了。在
8)我也尝试过使用URLConnection根据RFC2388编写原始的http multipart/form,结果类似。什么是webapp/webob/wsgi/whatever following?在
谢谢大家!在
这是我第一个主要的stackoverflow问题,希望我的格式都正确;-)
目前没有回答
相关问题 更多 >
编程相关推荐