文件上传至Android为503,但在REST客户机工作正常 [英] File upload through Android gives 503, but works fine in REST Client
问题描述
我用PHP编写的Web服务(在LAMP组合运行),我用它来上传文件并进行处理。
当我把这个从我的Android应用程序,服务器返回错误503
在Android上,如果我删除了文件上传部分,并通过其他参数,它的工作原理!
如果我评论的所有code,它仍然给错误。因此,它看起来像某种原因,通过Android上的文件上传不工作!
请注意:这是工作直到上周。上周我提出我的Web服务器,以新的托管(不同IP) - 这是所有。
如果我从Chrome中REST客户端测试,它工作完全正常!
不同的服务器(不同的域名和IP)在同一脚本正常工作。
这可能是什么错误?
为什么当我从Android应用程序调用它不仅不能!
下面是Android code:
的HttpClient HttpClient的=新DefaultHttpClient();
HttpPost httpPost =新HttpPost(的web_url);MultipartEntityBuilder建设者= MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);。InputStream为= PBAApplication.getInstance()的getContext()getContentResolver()openInputStream(fileURI所);
InputStreamBody ISB =新InputStreamBody(是,文件名);builder.addPart(类型,新StringBody(APPM));
builder.addPart(文件,ISB);httpPost.setEntity(builder.build());//执行HTTP请求
HTT presponse响应= httpClient.execute(httpPost);
Server错误日志显示如下:
(32)管道中断:客户219.74.158.38:21214] AH01075:错误调度请求:(发送标准输入)
有几件事情可以做,以解决:
- 修改服务器转储错误。
- 尝试主体内容类型设置为应用程序/ x-WWW的形式urlen codeD
- 确保链接正确的是(http和https)上。
- 看一下你的休息客户端的cookie,并确保你的头在应用程序相匹配。
要记录所有的通信通过HttpClient的打算,用这些终端命令:
//亚行外壳setprop log.tag.org.apache.http VERBOSE
//亚行外壳setprop log.tag.org.apache.http.wire VERBOSE
添加到您的应用程序类:
java.util.logging.Logger.getLogger(org.apache.http.wire)执行setLevel(java.util.logging.Level.FINEST)。
java.util.logging.Logger.getLogger(\"org.apache.http.headers\").setLevel(java.util.logging.Level.FINEST);
System.setProperty(org.apache.commons.logging.Log,org.apache.commons.logging.impl.SimpleLog);
System.setProperty(org.apache.commons.logging.simplelog.showdatetime,真);
System.setProperty(org.apache.commons.logging.simplelog.log.httpclient.wire,调试);
System.setProperty(org.apache.commons.logging.simplelog.log.org.apache.http,调试);
System.setProperty(org.apache.commons.logging.simplelog.log.org.apache.http.headers,调试);
System.setProperty(http.keepAlive,假);
I have a web service written in PHP (runs on LAMP stack) that I use to upload a file and process it.
When I call this from my android app, the server returns error 503.
In Android, if I remove the file upload part and pass other parameters, it works !!!
If I comment all the code, still it gives error. So it looks like for some reason the file upload via Android is not working !!
Note : It was working until last week. Last week I moved my web server to new hosting (different IP) - That's all.
If I test from Chrome Rest Client, it works perfectly fine !!!
Same script on a different server (different domain name and IP) works fine.
What could be the error ? Why does it fail only when I call from Android app !!
Following is the Android code:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(web_url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
InputStream is = PBAApplication.getInstance().getContext().getContentResolver().openInputStream(fileURI);
InputStreamBody isb = new InputStreamBody(is, fileName);
builder.addPart("type", new StringBody("APPM"));
builder.addPart("file", isb);
httpPost.setEntity(builder.build());
// Execute HTTP Request
HttpResponse response = httpClient.execute(httpPost);
Server error log shows this:
(32)Broken pipe: [client 219.74.158.38:21214] AH01075: Error dispatching request to : (sending stdin)
There are a few things you can do to troubleshoot:
- Modify the server to dump the error.
- Try setting body content type to application/x-www-form-urlencoded
- Make sure the url is correct (http vs https).
- Look at the cookies in your rest client and make sure your headers match in the app.
To log all traffic going through HttpClient, use these terminal commands:
// adb shell setprop log.tag.org.apache.http VERBOSE
// adb shell setprop log.tag.org.apache.http.wire VERBOSE
Add this to your Application class:
java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST);
java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST);
System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug");
System.setProperty("http.keepAlive", "false");
这篇关于文件上传至Android为503,但在REST客户机工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!