我是一个来自中国的新手程序员。我在使用google-geocoding api时遇到了一些问题,当我使用以下代码进行调试时,它是正确的,但当我在发布模式下使用生成的.exe文件编译时,没有响应。因为我在中国,所以我只能使用网络代理访问URL,所以我不知道是网络问题还是我的代码问题。有没有人可以帮我试一下下面的代码来检查这个问题。
// street_name.cpp :
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <Windows.h>
#include <wininet.h>
using namespace std;
#define MAXBLOCKSIZE 500
#pragma comment (lib, "wininet.lib")
void download(const char*);
int main(int argc, char* argv[]){
const char *cUrl = NULL;
char Url[512];
float lat = 45.798748;
float lng = 126.531115;
sprintf(Url,"https://maps.googleapis.com/maps/api/geocode/xml?latlng=45.797749,126.523811&result_type=route&address_component_type=route&key=AIzaSyC6M3Pbbjdrgtl8QZjuJPK-1JdAJD5oEgA",lat,lng);
cUrl = Url;
download(cUrl);
if (argc > 1)
{
download((const char*)argv[1]);
}
else
{
cout << "Usage: auto-Update url";
}
return 0;
}
/**
*
* @param Url: The target action url
*
*/
void download(const char *Url)
{
HINTERNET hSession = InternetOpenA("RookIE/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
string StreetName;
if (hSession != NULL)
{
HINTERNET handle2 = InternetOpenUrlA(hSession, Url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
if (handle2 != NULL)
{
cout << Url << endl;
byte Temp[MAXBLOCKSIZE] = {0};
ULONG Number = 1;
int i = 0;
ofstream ofs("baidu.txt");
if (ofs)
{
while (Number > 0)
{
InternetReadFile(handle2, Temp, MAXBLOCKSIZE - 1, &Number);
string a = string((const char*)Temp,Number);
ofs << a.c_str();
StreetName += a;
}
ofs.close();
}
InternetCloseHandle(handle2);
handle2 = NULL;
}
InternetCloseHandle(hSession);
hSession = NULL;
}
}发布于 2016-10-05 17:51:23
如果您的请求来自中国,可能是HTTPS请求被阻止。尝试使用HTTP。
我想这可能和https://meta.stackexchange.com/questions/191338/https-problem-when-accessing-stack-overflow-in-china有关
https://stackoverflow.com/questions/39791353
复制相似问题