使用Goo.gl API時,是否有辦法告訴它不要自動添加尾部斜槓?因爲它弄亂了很多網站,例如,如果你去:http://www.samsung.com/us/support/SupportOwnersFAQPopup.do?faq_id=FAQ00046726&fm_seq=49755與一個尾隨斜線它不起作用!有什麼建議麼?Goo.gl API自動添加尾部斜槓
我的代碼:
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();
}
你將有github repo here向我們展示一些代碼,以便我們可以看到你錯在哪裏。 – 2012-07-16 19:16:14
將該URL投入到goo.gl中會使我http://goo.gl/nugyd不會追加尾部斜線。你在問什麼? – 2012-07-16 19:17:16
@DanielDiPaolo我的意思是它給Long Url增加了一個斜槓 – 2012-07-16 19:18:23