如何形成一个url来生成goo.gl短网址?
在bit.ly中可以使用:
使用goo.gl API的文档
正常的申请表是:
POST https://www.googleapis.com/urlshortener/v1/url Content-Type:application / json
{“longUrl”:“URL”}
如何将此转换为网址?
答案 0 :(得分:3)
我使用Fiddler按照您的描述进行POST,并使用此问题的URL,如下所示:
POST /urlshortener/v1/url HTTP/1.1
User-Agent: Fiddler
Content-Type: application/json
Host: www.googleapis.com
Content-Length: 102
{"longUrl" : "http://stackoverflow.com/questions/5683562/formatting-url-to-generate-goo-gl-short-url"}
我得到的回应是,
HTTP/1.1 200 OK
ETag: "7EqIPxWjdFEMGopn0m-wh5UjU2M/mbXotpNse1SbcCFgA5pLLsB6hi4"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Sat, 16 Apr 2011 01:13:41 GMT
Content-Type: application/json; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Content-Length: 164
{
"kind": "urlshortener#url",
"id": "http://goo.gl/Ztc9b",
"longUrl": "http://stackoverflow.com/questions/5683562/formatting-url-to-generate-goo-gl-short-url"
}
这将是一个包含缩短URL的JSON表示。