首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SkyScanner SessionKey在哪里?

SkyScanner SessionKey在哪里?
EN

Stack Overflow用户
提问于 2016-10-20 11:07:28
回答 1查看 248关注 0票数 0

第一个SkyScanner文档说

回应细节

成功的响应不包含任何内容。要轮询预订详细信息的URL在响应的位置标头中指定。

How to retrieve Session key from Skyscanner API post request - Ruby这个链接说响应成功的->定位头返回"sessionKey“

我的问题是响应成功,但是位置标头返回空..。

我使用Okhttp lib和

这是我的密码

代码语言:javascript
复制
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/Response:代码: 200 10-20 20:01:00.698 22202-22408/com.example.park.myapplication V/Response:消息: OK 10-20 20:01:00.698 22202-22408/com.example.park.myapplication V/Response:location : null

我该怎么办?请找到我的会话钥匙..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-26 03:04:35

变更库-> HttpurlConnection..。

尝试{ url = new (U);HttpURLConnection connection = (HttpURLConnection)url.openConnection();

代码语言:javascript
复制
        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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40152705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档