Discussion:
HttpSendRequest fails returns ERROR_INTERNET_NAME_NOT_RESOLVED
(too old to reply)
Mo
2006-09-07 01:14:06 UTC
Permalink
Hello All,
i am really new to the WinInet world, i am developing an application
where
my app will request a server listing, each user
will have to login, upon successful login the server will print out
the file listing for that particular user

the server is local public machine http://public.xx.yyyy.com/zzzz
if i add the username and password to the above URL the php script
will then print the user listing


however, i dont want to post the URL in my app, i would like to POST
the username/password pair using HTTP headers
so i used the following schema

InternetOpen()
InternetConnect()
HttpOpenRequest()
HttpAddRequestHeaders()
HttpSendRequest()
InternetReadFile()

however HttpSendRequest fails and it returns
ERROR_INTERNET_NAME_NOT_RESOLVED, InternetReadFile() also fails
if i do this from my pc browser it works fine

http://public.xx.yyyy.com/zzzz/list/?user=user1&pass=password1

is there is anything i am missing? my code is below
the error code is confusing since the above request works from my
browser

appreciate your help
Mo

<code>

//open an internet connection
hOpenHandle = InternetOpen(szAgent,INTERNET_OPEN_TYPE_DIRECT, NULL,
NULL, NULL);
if(NULL == hOpenHandle)
{
dwErrorCode = GetLastError();
printf("dwErrorCode=%x\r\n",dwErrorCode);
return FALSE;
}

hConnectHandle = InternetConnect(hOpenHandle
,TEXT("http://public.xx.yyyy.com/zzzz"),
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP,
INTERNET_FLAG_PASSIVE, 0 );

if (NULL ==hConnectHandle)
{
dwErrorCode=GetLastError();
printf("dwErrorCode=%x\r\n",dwErrorCode);
return FALSE;
}


hHttpOpenRequest = HttpOpenRequest(hConnectHandle,
TEXT("POST"),TEXT("/list/?"),TEXT("HTTP/1.0"), NULL, 0,
INTERNET_FLAG_RELOAD, 0);


if (NULL == hHttpOpenRequest || GetLastError() ==
ERROR_INTERNET_NAME_NOT_RESOLVED)
{
InternetCloseHandle(hConnectHandle);
InternetCloseHandle(hOpenHandle);
printf("HttpOpenRequest failed, error = %d (0x%x)\n",GetLastError());
return 0;
}
TCHAR sHeader[] = TEXT("Content-Type:
application/x-www-form-urlencoded\r\n");
size_t length;
StringCchLength(sHeader,MAX_PATH,&length);

bResult = HttpAddRequestHeaders(hHttpOpenRequest,
sHeader, length, HTTP_ADDREQ_FLAG_REPLACE|HTTP_ADDREQ_FLAG_ADD);
if(!bResult)
{
dwErrorCode=GetLastError();
printf("Error code =%d",dwErrorCode);

}


TCHAR lpszPostData[] = TEXT("user=username1&password=password1\r\n");
StringCchLength(lpszPostData,MAX_PATH,&length);

bResult = HttpSendRequest(hHttpOpenRequest,
NULL,
0,
lpszPostData,
length);
if(!bResult)
{
dwErrorCode=GetLastError();
printf("Error code =%d",dwErrorCode);

}
//read the server listing
while(InternetReadFile( hHttpOpenRequest, buffer, sizeof(buffer),
&dwRead ))
{
if ( dwRead == 0 )
break;
buffer[dwRead] = 0;
dwTotalBytesRead+=dwRead;
}
</code>
Vladimir Scherbina
2006-09-07 05:53:36 UTC
Permalink
This post might be inappropriate. Click to display it.
Mo
2006-09-07 18:31:28 UTC
Permalink
Hey Vladimir
thanks for your help, that helped ;-)
i also realised that i needed to add index.php to my relative path
for HttpOpenRequest so its like "zzz/list/index.php"

now, i need to know how to format the post data ?
is it "user=username1&password=password1"? this is not working for me


thanks
Mo
Post by Vladimir Scherbina
Mo,
- in InternetConnect you should specify the server name not the whole path,
i.e. public.xxx.yyy.com NOT http://public.xxx.yyy.com/zzz !
- in HttpOpenRequest you should put relative path: /zzz/list/
Apply these two changes and report us the result.
HTH
--
Vladimir
Post by Mo
Hello All,
i am really new to the WinInet world, i am developing an application
where
my app will request a server listing, each user
will have to login, upon successful login the server will print out
the file listing for that particular user
the server is local public machine http://public.xx.yyyy.com/zzzz
if i add the username and password to the above URL the php script
will then print the user listing
however, i dont want to post the URL in my app, i would like to POST
the username/password pair using HTTP headers
so i used the following schema
InternetOpen()
InternetConnect()
HttpOpenRequest()
HttpAddRequestHeaders()
HttpSendRequest()
InternetReadFile()
however HttpSendRequest fails and it returns
ERROR_INTERNET_NAME_NOT_RESOLVED, InternetReadFile() also fails
if i do this from my pc browser it works fine
http://public.xx.yyyy.com/zzzz/list/?user=user1&pass=password1
is there is anything i am missing? my code is below
the error code is confusing since the above request works from my
browser
appreciate your help
Mo
<code>
//open an internet connection
hOpenHandle = InternetOpen(szAgent,INTERNET_OPEN_TYPE_DIRECT, NULL,
NULL, NULL);
if(NULL == hOpenHandle)
{
dwErrorCode = GetLastError();
printf("dwErrorCode=%x\r\n",dwErrorCode);
return FALSE;
}
hConnectHandle = InternetConnect(hOpenHandle
,TEXT("http://public.xx.yyyy.com/zzzz"),
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP,
INTERNET_FLAG_PASSIVE, 0 );
if (NULL ==hConnectHandle)
{
dwErrorCode=GetLastError();
printf("dwErrorCode=%x\r\n",dwErrorCode);
return FALSE;
}
hHttpOpenRequest = HttpOpenRequest(hConnectHandle,
TEXT("POST"),TEXT("/list/?"),TEXT("HTTP/1.0"), NULL, 0,
INTERNET_FLAG_RELOAD, 0);
if (NULL == hHttpOpenRequest || GetLastError() ==
ERROR_INTERNET_NAME_NOT_RESOLVED)
{
InternetCloseHandle(hConnectHandle);
InternetCloseHandle(hOpenHandle);
printf("HttpOpenRequest failed, error = %d (0x%x)\n",GetLastError());
return 0;
}
application/x-www-form-urlencoded\r\n");
size_t length;
StringCchLength(sHeader,MAX_PATH,&length);
bResult = HttpAddRequestHeaders(hHttpOpenRequest,
sHeader, length, HTTP_ADDREQ_FLAG_REPLACE|HTTP_ADDREQ_FLAG_ADD);
if(!bResult)
{
dwErrorCode=GetLastError();
printf("Error code =%d",dwErrorCode);
}
TCHAR lpszPostData[] = TEXT("user=username1&password=password1\r\n");
StringCchLength(lpszPostData,MAX_PATH,&length);
bResult = HttpSendRequest(hHttpOpenRequest,
NULL,
0,
lpszPostData,
length);
if(!bResult)
{
dwErrorCode=GetLastError();
printf("Error code =%d",dwErrorCode);
}
//read the server listing
while(InternetReadFile( hHttpOpenRequest, buffer, sizeof(buffer),
&dwRead ))
{
if ( dwRead == 0 )
break;
buffer[dwRead] = 0;
dwTotalBytesRead+=dwRead;
}
</code>
Vladimir Scherbina
2006-09-07 21:19:58 UTC
Permalink
You're welcome Mo.

As you wrote when you typed in browser full link all worked fine, so simply
put GET instead of POST when calling HttpOpenRequest. If this does not help
then most likely you composed wrong request data: sniffer is the best helper
in this case - IRIS is still very powerfull one ...
--
Vladimir
Post by Mo
Hey Vladimir
thanks for your help, that helped ;-)
i also realised that i needed to add index.php to my relative path
for HttpOpenRequest so its like "zzz/list/index.php"
now, i need to know how to format the post data ?
is it "user=username1&password=password1"? this is not working for me
thanks
Mo
Post by Vladimir Scherbina
Mo,
- in InternetConnect you should specify the server name not the whole path,
i.e. public.xxx.yyy.com NOT http://public.xxx.yyy.com/zzz !
- in HttpOpenRequest you should put relative path: /zzz/list/
Apply these two changes and report us the result.
HTH
--
Vladimir
Post by Mo
Hello All,
i am really new to the WinInet world, i am developing an application
where
my app will request a server listing, each user
will have to login, upon successful login the server will print out
the file listing for that particular user
the server is local public machine http://public.xx.yyyy.com/zzzz
if i add the username and password to the above URL the php script
will then print the user listing
however, i dont want to post the URL in my app, i would like to POST
the username/password pair using HTTP headers
so i used the following schema
InternetOpen()
InternetConnect()
HttpOpenRequest()
HttpAddRequestHeaders()
HttpSendRequest()
InternetReadFile()
however HttpSendRequest fails and it returns
ERROR_INTERNET_NAME_NOT_RESOLVED, InternetReadFile() also fails
if i do this from my pc browser it works fine
http://public.xx.yyyy.com/zzzz/list/?user=user1&pass=password1
is there is anything i am missing? my code is below
the error code is confusing since the above request works from my
browser
appreciate your help
Mo
<code>
//open an internet connection
hOpenHandle = InternetOpen(szAgent,INTERNET_OPEN_TYPE_DIRECT, NULL,
NULL, NULL);
if(NULL == hOpenHandle)
{
dwErrorCode = GetLastError();
printf("dwErrorCode=%x\r\n",dwErrorCode);
return FALSE;
}
hConnectHandle = InternetConnect(hOpenHandle
,TEXT("http://public.xx.yyyy.com/zzzz"),
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP,
INTERNET_FLAG_PASSIVE, 0 );
if (NULL ==hConnectHandle)
{
dwErrorCode=GetLastError();
printf("dwErrorCode=%x\r\n",dwErrorCode);
return FALSE;
}
hHttpOpenRequest = HttpOpenRequest(hConnectHandle,
TEXT("POST"),TEXT("/list/?"),TEXT("HTTP/1.0"), NULL, 0,
INTERNET_FLAG_RELOAD, 0);
if (NULL == hHttpOpenRequest || GetLastError() ==
ERROR_INTERNET_NAME_NOT_RESOLVED)
{
InternetCloseHandle(hConnectHandle);
InternetCloseHandle(hOpenHandle);
printf("HttpOpenRequest failed, error = %d (0x%x)\n",GetLastError());
return 0;
}
application/x-www-form-urlencoded\r\n");
size_t length;
StringCchLength(sHeader,MAX_PATH,&length);
bResult = HttpAddRequestHeaders(hHttpOpenRequest,
sHeader, length, HTTP_ADDREQ_FLAG_REPLACE|HTTP_ADDREQ_FLAG_ADD);
if(!bResult)
{
dwErrorCode=GetLastError();
printf("Error code =%d",dwErrorCode);
}
TCHAR lpszPostData[] = TEXT("user=username1&password=password1\r\n");
StringCchLength(lpszPostData,MAX_PATH,&length);
bResult = HttpSendRequest(hHttpOpenRequest,
NULL,
0,
lpszPostData,
length);
if(!bResult)
{
dwErrorCode=GetLastError();
printf("Error code =%d",dwErrorCode);
}
//read the server listing
while(InternetReadFile( hHttpOpenRequest, buffer, sizeof(buffer),
&dwRead ))
{
if ( dwRead == 0 )
break;
buffer[dwRead] = 0;
dwTotalBytesRead+=dwRead;
}
</code>
Loading...