LoginSignup
2
2

More than 5 years have passed since last update.

WEB APIで の json取得時に http header に content-type:Application/json を付加するとPOSTリクエストが無効になる

Posted at

\WEB API側の設計によるのかもしれないけど…

当方の環境

xCode4.3からNSURLConnection で PHP で記述されたWEB APIにアクセス。サーバはApache+Postgres。
http body にリクエストキューを格納し、POSTでhttp requestを送信するも戻り値が取得できなかったので少しハマった。
Apacheのlog上でもPOSTで記録されているが、試しにPHP側で 'GET ならここ' の条件分岐を置くとそこに入る。

原因が分からなかったので少しずつコードをいじってわかったのが

[urlRequest setValue:@"application/json;" forHTTPHeaderField:@"content-type"];

を付加すると発生する現象だと判明。

[urlRequest setValue:@"application/x-www-form-urlencoded;" forHTTPHeaderField:@"content-type"];

にて解決。

こういう感じで書けばいいのかな??

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2