2017-05-19 3 views
0

간단한 파일 다운로드 테스트. 작동 안함. 회사에서 프록시 때문에 프로백. 어떻게 프록시를 구성 할 수 있습니까? "127.0.0.1:8080"을 추가하기 전에 항상 오류 7이 발생했습니다 : 서버에 연결할 수 없습니다. 이제는 항상 return code 0을 얻지 만 json.txt 테스트 파일에는 404 만 포함되어 있습니다. 그러나 URL은 분명히 브라우저에서 작동합니다. 또한 this을 통해 시스템에서 프록시 설정을 가져 오려고했지만 실패했습니다. 인터넷 설정이 프록시를 감지하기 위해 wpad.dat 파일을 사용하도록 구성되어프록시 뒤에 cURL 404

CURL *curl; 
FILE *fp; 
char url[] = "http://www.carqueryapi.com/api/0.3/?callback=?&cmd=getMakes&year=2010&sold_in_us=1"; 
char outfilename[FILENAME_MAX] = "C:\\temp\\json.txt"; 
curl = curl_easy_init(); 
if (curl) { 
    fp = fopen(outfilename,"wb"); 

    CURLcode res; 
    curl_easy_setopt(curl, CURLOPT_URL, url); 
    curl_easy_setopt(curl, CURLOPT_NOBODY, true); 
    curl_easy_setopt(curl, CURLOPT_HEADER, true); 
    curl_easy_setopt(curl, CURLOPT_HTTPGET, true); 
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); 
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_easy_setopt(curl, CURLOPT_PROXY, "127.0.0.1:8080"); 

    res = curl_easy_perform(curl); 
    cout << "Curl response code " << res << ": " << curl_easy_strerror(res) << endl; 

    curl_easy_cleanup(curl); 

    fclose(fp); 
} 

UPDATE :

HTTP/1.1 404 Not Found 
Connection: Keep-Alive 
Server: Embedthis-http 
ETag: "0-0-56d6b6ea" 
Cache-Control: no-cache 
Last-Modified: Wed, 02 Mar 2016 09:48:26 GMT 
Date: Fri, 19 May 2017 14:33:57 GMT 
Content-Length: 167 
Keep-Alive: timeout=60, max=199 

<!DOCTYPE html> 
<html><head><title>Not Found</title></head> 
<body> 
<h2>Access Error: 404 -- Not Found</h2> 
<pre>Cannot locate document: /</pre> 
</body> 
</html> 

여기 내 컬을 시도이다. 그 중 하나를 입력하면 서버에서 응답을 얻지 만 웹 사이트가 차단되어 액세스가 거부되었다고 말합니다. 하지만 내 브라우저에서이 사이트를 표시 할 수 있습니다.

반대로, 내가 netsh.exe winhttp show proxy을 입력하면 현재 winhttp 프록시 설정이 "직접 액세스 (프록시 서버 없음)"라고 표시됩니다.

UPDATE 나는 마침내 그 옵션 작업있어 2

: 더 도움이 출력을 얻을 수 Verbose을 사용; 출력은 negotiatentlm과 같은 인증 방법을 보여주었습니다. ntlm 옵션이 작동하지 않았지만 libcurl에 sspi 모듈이있는 경우 이 시스템에서 자격 증명을 가져 오는 : 사용자 프로필과 함께 사용되었습니다.

curl_easy_setopt(curl, CURLOPT_URL, url); 
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); 
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); 
    curl_easy_setopt(curl, CURLOPT_HEADER, 1); 
    curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
    curl_easy_setopt(curl, CURLOPT_PROXY, <"host:port">); 
    curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_NEGOTIATE); 
    curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, ":"); 

답변

0

사용자 에이전트를 사용해 헤더를 정의하십시오.

#define HEADER_ACCEPT "Accept:text/html,application/xhtml+xml,application/xml" 
#define HEADER_USER_AGENT "User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.70 Safari/537.17" 

struct curl_slist *list = NULL; 
list = curl_slist_append(list, HEADER_USER_AGENT); 
list = curl_slist_append(list, HEADER_ACCEPT); 
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); 

당신은 진정한 프록시를 필요 프록시 사이트를 발견하고 그것은 여전히 ​​작동하지 않는 다른 IP

+0

으로 다시 시도 할 수 있습니다. – user2366975