POST リクエストではすべて問題ありませんが、PUT または DELETE で作業する方法が見つかりませんか?
NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] init];
[mutableRequest setURL:[NSURL URLWithString:[NSString
stringWithFormat:@"http://abc.com/update/27"]]];
[mutableRequest setHTTPMethod:@"PUT"];
[mutableRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"];
[mutableRequest addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[mutableRequest addValue:@"PUT" forHTTPHeaderField:@"X-HTTP-Method-Override"];
[mutableRequest addValue:sessionId forHTTPHeaderField:@"ZURMO_SESSION_ID"];
[mutableRequest addValue:token forHTTPHeaderField:@"ZURMO_TOKEN"];
[mutableRequest addValue:@"REST" forHTTPHeaderField:@"ZURMO_API_REQUEST_TYPE"];
NSString *postLength = [NSString stringWithFormat:@"%d",[postdata3 length]];
[mutableRequest addValue:postLength forHTTPHeaderField:@"Content-Length"];
[mutableRequest setHTTPBody:postdata3]
これは、サーバー側 (PHP) が PUT、GET、POST、および DELETE を使用して API 呼び出しを処理する方法です。どんな助けでも感謝します
public static function createApiCall($url, $method, $headers, $data = array())
{
if ($method == 'PUT')
{
$headers[] = 'X-HTTP-Method-Override: PUT'; //also tried this one to add header
}
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
switch($method)
{
case 'GET':
break;
case 'POST':
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data));
break;
case 'PUT':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($data));
break;
case 'DELETE':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
}
$response = curl_exec($handle);
return $response;
}