ios - PUT 请求状态码 500?
<p><p>我在 Objective C 中实现了一个 PUT 请求。使用 Postman 从 iOS/Objective C 外部执行该请求时成功,但在 Objective C 中调用时返回错误(状态代码 500)。据我所知,该实现反射(reflect)了在 Postman 中设置调用的方式。这是我尝试使用 Objective C 镜像的调用:</p>
<p> <a href="/image/i7h2A.png" rel="noreferrer noopener nofollow"><img src="/image/i7h2A.png" alt="enter image description here"/></a> </p>
<p> <a href="/image/Tic9x.png" rel="noreferrer noopener nofollow"><img src="/image/Tic9x.png" alt="enter image description here"/></a> </p>
<p>这是我在 Objective C 中的实现:</p>
<pre><code>- (void)callUnregisterForPushNotifications:(NSString *)accessToken
pushToken:(NSString *)pushToken
completionBlock:(void (^)(NSMutableArray *resultsArray))completion{
NSLog(@"UNREGISTER FOR PUSH CALLED!");
NSLog(@"PUSH TOKEN %@", pushToken);
NSString *appendUrl = @"alerts/unregisterpush/";
NSLog(@"APPEND URL %@",appendUrl);
NSURL *unregisterUrl = ];
NSLog(@"UNREGISTER URL: %@",unregisterUrl);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:unregisterUrl
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
;
NSString *appendToken = ;
NSLog(@"TOKEN: %@",appendToken);
;
NSString *postString = ;
NSLog(@"POST STRING: %@",postString);
];
NSLog(@"REQUEST %@",request);
[NSURLConnection sendAsynchronousRequest:request
queue:
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSLog(@"UNREGISTER PUSH NOTIFICATIONS RESPONSE: %@", response);
NSLog(@"UNREGISTER PUSH NOTIFICATIONS ERROR: %@", error);
NSLog(@"UNREGISTER PUSH NOTIFICATIONS DATA: %@", data);
NSData *_data = data;// ... whatever
NSMutableString *_string = ;
for (int i = 0; i < _data.length; i++) {
unsigned char _byte;
;
if (_byte >= 32 && _byte < 127) {
;
} else {
", _byte];
}
}
NSLog(@"UNREGISTER PUSH RESPONSE: %@", _string);
id obj= ;
if (!obj) {
//NSLog(@"REGISTER PUSH NOTIFICATIONS ERROR: %@", error);
} else {
//NSLog(@"REGISTER PUSH NOTIFICATIONS DATA: %@", obj);
if(completion) {
[ setNetworkActivityIndicatorVisible:NO];
completion((NSMutableArray*)obj);
}
//self.accessToken = ;
//NSLog(@"ACCESS TOKEN: %@",self.accessToken);
}
}];
}
</code></pre>
<p>任何输入/帮助将不胜感激,在此先感谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这一行:</p>
<pre><code>NSString *postString = ;
</code></pre>
<p>与您在 Postman 中显示的内容不符。</p>
<ol>
<li>对象周围缺少 <code>{ }</code></li>
<li>字段和值周围缺少 <code>""</code></li>
<li>缺少 <code>Accept</code> 和 <code>Content-type</code>header </li>
</ol></p>
<p style="font-size: 20px;">关于ios - PUT 请求状态码 500?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35709205/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35709205/
</a>
</p>
页:
[1]