我想向服务器发送一个请求,一个带有以下请求标头的 PUT 请求:
Content-Type: application/json; charset=UTF-8
以及以下内容NSDictionary
:
{"title": "Sumit"}
我正在使用 reskit 发出 put 请求,发出了 put 请求但给出了与标头相关的错误。我想知道在向远程服务器发送请求时如何设置标头和字典。此外,哪种方法最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