2016-07-07 9 views
0

非常に単純なJSONを返すAPIがあります。郵便配達のREST POST APIがAlamofireで動作するのは動作しません

まず、apiを含むサーバーがローカルマシン(ローカルホスト)にありました。この場合、すべて正常に動作します。

:私はホスティングAPIに(Alamofireを使用して)iPhoneアプリから接続しようとしたときに

私はresponse.responseがある。この場合、

Alamofire.request(.POST, "https://domain.com/api/search", parameters: ["ubicacion": ubicacionId, "fecha":"\(dateFormatter.stringFromDate(fecha))"], encoding: .URL) 
      .responseJSON { response in 
       switch response.result { 
       case .Success: 
        print(response.request) // original URL request 
        print(response.response) // URL response 
        print(response.result) // result of response serialization 
        self.JSON = response.result.value! 
        //llamar el delegate 
        self.delegate.devolverjson(self.JSON) 
       case .Failure(let error): 
        print(response.request) // original URL request 
        print(response.response) // URL response 
        print(response.result) // result of response serialization 
        self.JSON = ["error":error] 
        //llamar el delegate 
        self.delegate.devolvererror(self.JSON) 
       } 
     } 

を動作しない、ウェブホスティングAPIを渡します

{ URL: https://domain.com/api/search } { status code: 405, headers { 
    "Cache-Control" = "no-cache, private"; 
    Connection = "Keep-Alive"; 
    "Content-Type" = "text/html; charset=UTF-8"; 
    Date = "Thu, 07 Jul 2016 18:24:26 GMT"; 
    "Keep-Alive" = "timeout=3, max=30"; 
    Server = "Apache Phusion_Passenger/4.0.10 mod_bwlimited/1.4 mod_fcgid/2.3.9"; 
    "Transfer-Encoding" = Identity; 
    "X-Powered-By" = "PHP/5.6.22"; 
    allow = POST; 
} }) 

response.result.Failure

とエラーされている

error: { 
    error = "Error Domain=NSCocoaErrorDomain Code=3840 \"Invalid value around character 0.\" UserInfo={NSDebugDescription=Invalid value around character 0.}"; 
} 

Iは、API(同じURL:https://domain.com/api/search)に接続ポストマンからのAPIは、正しい情報(JSON)を返し、このヘッダを聖霊降臨祭。

Cache-Control →no-cache 
Connection →Keep-Alive 
Content-Type →application/json 
Date →Thu, 07 Jul 2016 18:23:38 GMT 
Keep-Alive →timeout=3, max=30 
Server →Apache Phusion_Passenger/4.0.10 mod_bwlimited/1.4 mod_fcgid/2.3.9 
Transfer-Encoding →chunked 
X-Powered-By →PHP/5.6.22 

APIがPostmanと連携する場合、Alamofireで動作しないのはなぜですか?英語

+0

私はあなたの郵便配達パラメータキーのキーのコンテンツ異なっていたがあれば、キーの同じ –

+0

要求キーと同じではないと思います型はJSON @AkshanshThakur – dieroste

+0

は同じ問題があるはずです –

答えて

-1

response.requestあなたはポストマンにしようとしたURLと一致してい正しくない場合

はすみません? .POSTではなくAlamofire.request(.GET、url)を試しましたか? 私は1つのプロジェクトのパラメータにいくつかの問題があったので、代わりに私の前に私のURLを定式化し、Alamofireをパラメータなしで使用しました。

+0

はい、同じURLです。また、.TPOSTの代わりに.GETを使用すると、ステータスコードは、POSTを使用するときに取得される405の代わりに403になります – dieroste

0

はあなたのURLにスラッシュを末尾に追加してください:

https://domain.com/api/search/

関連する問題