gpt4 book ai didi

java - Goo.gl API 自动添加尾部斜杠

转载 作者:行者123 更新时间:2023-12-01 19:03:01 26 4
gpt4 key购买 nike

当使用 Goo.gl API 时,有没有办法告诉它不要自动添加尾部斜杠?因为它弄乱了很多网站,例如如果您访问:http://www.samsung.com/us/support/SupportOwnersFAQPopup.do?faq_id=FAQ00046726&fm_seq=49755带有尾部斜杠是行不通的!有什么建议吗?

我的代码:

  address= "https://www.googleapis.com/urlshortener/v1/url?key=xxxxxxxxxxxxx"
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(address);
try {
post.setEntity(new StringEntity("{\"longUrl\": \"" +longurl+ "/\"}"));
post.setHeader("Content-Type", "application/json");
if (userLogin == true) {
post.setHeader("Authorization", "OAuth "+accessToken);
}

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
org.apache.http.HttpResponse response = client.execute(post);
String responseBody = EntityUtils.toString(response.getEntity());
JSONObject object = (JSONObject) new JSONTokener(responseBody).nextValue();
query = object.getString("id");
shortUrl = query;
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}

最佳答案

post.setEntity(new StringEntity("{\"longUrl\": \"" +longurl+ "/\"}"));
// I think I found the problem -------------------------------^

您自己在 longurl 后添加斜杠,goo.gl 没有这样做。

关于java - Goo.gl API 自动添加尾部斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11510988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com