1
保存在覈心數據響應我要發送到服務器上,使用以下請求標頭的PUT請求的請求:PUT請求,更改標題和使用RESTkit
Content-Type: application/json; charset=UTF-8
而下面NSDictionary
:
{"title": "Sumit"}
我正在做一個使用reskit的請求,提出了請求,但給出了有關頭的錯誤。 我想知道如何在向遠程服務器發送請求時設置標題和字典。 另外,該方法是最好的RKObjectManager
對之間的這種任務: -
方法1: -
- NSMutableURLRequest *request = [manager requestWithObject:newImage
method:RKRequestMethodPUT
path:[kImageUrl stringByAppendingString:imageUrl]
parameters:jsonParameters];
方法2: -
- (NSMutableURLRequest *)multipartFormRequestWithObject:(id)object
method:(RKRequestMethod)method
path:(NSString *)path
parameters:(NSDictionary *)parameters
constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block;
錯誤我得到: -
(400 Bad Request) [0.4221 s]: Error Domain=AFNetworkingErrorDomain Code=-1016
"Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/plain" UserInfo=0xa0951c0 {NSLocalizedRecoverySuggestion=Bad Request,
AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest
http://staging.zoomdeck.com/api/image/c5ot31sxnh8v/>,
NSErrorFailingURLKey=http://staging.zoomdeck.com/api/image/c5ot31sxnh8v/,
NSLocalizedDescription=Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/plain, AFNetworkingOperationFailingURLResponseErrorKey=<
NSHTTPURLResponse: 0xa194530>}
2013-01-16 17:19:43.860 Zoomdeck[2905:4a07] E
restkit.network:RKObjectRequestOperation.m:285 Object request failed:
Underlying HTTP request operation failed with error: Error
Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/plain" UserInfo=0xa0951c0 {NSLocalizedRecoverySuggestion=Bad Request,
AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest
http://staging.zoomdeck.com/api/image/c5ot31sxnh8v/>,
NSErrorFailingURLKey=http://staging.zoomdeck.com/api/image/c5ot31sxnh8v/,
NSLocalizedDescription=Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/plain, AFNetworkingOperationFailingURLResponseErrorKey=
<NSHTTPURLResponse: 0xa194530>}
2013-01-16 17:19:43.861 Zoomdeck[2905:c07] Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/plain
謝謝,我嘗試了很多像這樣的方法...但在restkit處理完成的內部是某種方式,由於我一直這樣做除此之外,我們可以在製作NSMutableRequest對象之前進行設置。 manager.requestSerializationMIMEType = RKMIMETypeJSON;它現在通過這個工作... – Sumitiscreative