0

最初の SkyScanner Document と言う

回答の詳細

正常な応答にはコンテンツが含まれていません。予約の詳細をポーリングする URL は、応答の Location ヘッダーで指定されます。

Skyscanner API ポスト リクエストからセッション キーを取得する方法 - Ruby this link say response successfully -> Location header return "sessionKey"

私の問題は応答が成功したことですが、Location ヘッダーは null を返します...

私はOkhttp libを使用し、

これが私のコードです

public String post(String url, String json) throws IOException {
    try {
        RequestBody body = RequestBody.create(JSON, json);

        Request request = new Request
                .Builder()
                .url(url)
                .post(body)
                .addHeader("Content-Type", "application/x-www-form-urlencode")
                .addHeader("Accept", "application/json")
                .build();

        Response response = client.newCall(request).execute();


        Log.v("Response", "code : " + response.code());
        Log.v("Response", "message : " + response.message());
        Log.v("Response", "location : " + response.header("location"));
        return response.body().string();
    } catch (Exception e) {
        return "";
    }
}

そして私のログ

10-20 20:01:00.698 22202-22408/com.example.park.myapplication V/応答:コード: 200

10-20 20:01:00.698 22202-22408/com.example.park.myapplication V/応答:メッセージ: OK

10-20 20:01:00.698 22202-22408/com.example.park.myapplication V/応答:場所: null

私は何をすべきか?私のセッションキーを見つけてください...

4

1 に答える 1

0

lib Okhttp を変更 -> HttpurlConnection...

{ url = 新しい URL(u); を試してください。HttpURLConnection 接続 = (HttpURLConnection)url.openConnection();

        connection.setRequestMethod("POST");
        connection.setConnectTimeout(500 * 1000);
        connection.setReadTimeout(500 * 1000);
        connection.setRequestProperty("Cache-Control", "no-cache");
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection.setRequestProperty("Accept", "application/xml");
        connection.setDoOutput(true);
        connection.setDoInput(true);


        String Parameters = "apiKey=" + apiKey +
                "&country=UK" +
                "&currency=GBP" +
                "&locale=en-GB" +
                "&originplace=EDI" +
                "&destinationplace=LHR" +
                "&outbounddate=2016-11-01" +
                "&intbounddate=2016-11-08" +
                "&locationschema=Iata" +
                "&adults=1";
        //Parameter 컨텐트 길이 넘겨주는 부분
        byte[] postData = Parameters.getBytes(StandardCharsets.UTF_8);
        int postDataLength = postData.length;
        connection.setRequestProperty("Content-Length", Integer.toString(postDataLength));
        OutputStream os = connection.getOutputStream();
        os.write(postData);
        os.flush();



        int responseCode = connection.getResponseCode();
于 2016-10-26T03:04:35.553 に答える