No response data from image upload POST

I'm currently uploading images to a Django server using the standard multipart/form-data Content-Type method and NSURLConnection. The image is uploaded correctly with no issues, but I don't receive the simple JSON response that should be returned. On the iPhone

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data

is never called, even though the request finishes with a HTTP 200.

I ended up changing the server code to immediately return something like:

{ success: 1 }

but the phone never gets this back after uploading. If I simply remove the image data from the POST, it seems like I get the JSON back successfully. I assume the multipart/form-data Content-Type that the phone sends is preventing any sort of response? How can I upload the image and expect a response?

I found it strange that this "no response data" behavior appears on an external https server, but not on a local dev server, both using the same code.


Try logging the output. Don't know what library you might be using. I suggest SBJSON if you still are fairly early in your project.

If you decide so just add this line to your json POST

[json setDebugOutput = TRUE]

It would give you a detailed output of whats happening when reaching the server. Fish a little around the library you are using, it should definitely have some debug output method.

链接地址: http://www.djcxy.com/p/75400.html

上一篇: 用json对象android多部分图像上传

下一篇: 没有来自图像上传POST的响应数据