diff options
-rw-r--r-- | getabook.c | 8 | ||||
-rw-r--r-- | util.c | 6 |
2 files changed, 8 insertions, 6 deletions
@@ -15,7 +15,7 @@ " -n download pages from numbers in stdin\n" \ " otherwise, all available pages will be downloaded\n" -#define USESSL 0 +#define USESSL 1 #define URLMAX 2048 #define STRMAX 1024 #define MAXPAGES 9999 @@ -75,8 +75,10 @@ int getpagelist() snprintf(url, URLMAX, "/gp/search-inside/service-data?method=getBookData&asin=%s", bookid); - if(!get("www.amazon.com", USESSL, url, NULL, NULL, &buf, 1)) + if(!get("www.amazon.com", USESSL, url, NULL, NULL, &buf, 1)) { + fprintf(stderr, "failed to get url %s\n", url); return 1; + } /* amazon have a canonical asin, which is needed to get all available pages */ if((s = strstr(buf, "\"ASIN\":\"")) != NULL) { @@ -154,7 +156,7 @@ int getpage(Page *page) return 1; } - if(!sscanf(page->url, "http://%[^/]/", host)) { + if(!sscanf(page->url, "https://%[^/]/", host)) { fprintf(stderr, "can't parse host of %s\n", page->url); return 1; } @@ -146,8 +146,7 @@ int request(char *host, int ssl, char *request, char *savecookie, char **body, i cur = pos + 2; if(sscanf(headline, "HTTP/%d.%d %d", &i, &i, &p) == 3 && p != 200) { - if(p == 403) - fprintf(stderr, "403 forbidden: your IP address may be temporarily blocked\n"); + fprintf(stderr, "HTTP code %d; your IP address may be temporarily blocked\n", p); free(buf); free(*body); return 0; @@ -178,7 +177,8 @@ int get(char *host, int ssl, char *path, char *sendcookie, char *savecookie, cha if(sendcookie && sendcookie[0]) snprintf(c, COOKIEMAX, "\r\nCookie: %s", sendcookie); snprintf(h, BUFSIZ, "GET %s HTTP/1.0\r\nUser-Agent: getxbook-"VERSION \ - " (not mozilla)\r\nHost: %s%s\r\n\r\n", path, host, c); + " (not mozilla)\r\nAccept-Encoding: gzip;q=0,deflate;q=0\r\n" \ + "Host: %s%s\r\n\r\n", path, host, c); return request(host, ssl, h, savecookie, body, istext); } |