InternetCrackUrl() function

浪子不回头ぞ 提交于 2019-12-14 03:16:15

问题


I've got a little problem with this function when I'm trying to crack my URL in URL_COMPONENTS structure, the value of HostName and urlPath members stays on '\0' and meanwhile it's so, I have the true Length of both(HostName and urlPath members). what is the problem?, it' would be my pleasure if you answer by code.

Thanks and best wishes, John Smith.

URL_COMPONENTS urlcomponents;
urlcomponents.dwStructSize=sizeof(URL_COMPONENTS);
urlcomponents.dwHostNameLength=10;
urlcomponents.dwPasswordLength=10;
urlcomponents.dwSchemeLength=10;
urlcomponents.dwUrlPathLength=10;
urlcomponents.dwUserNameLength=10;
urlcomponents.dwExtraInfoLength=10;
urlcomponents.lpszExtraInfo=extraInfo;
urlcomponents.lpszHostName=hostName;
urlcomponents.lpszPassword=passwordSet;
urlcomponents.lpszScheme=schemeUrl;
urlcomponents.lpszUrlPath=fileUrlPath;
urlcomponents.lpszUserName=userName;
//urlcomponents.nPort=80;

std::string originUrl="http://s1.asandownload.com/mobile/android/application/Color.Effect.Booth.Pro.v1.4.2_AsanDl.com.apk";

InternetCrackUrl(originUrl.c_str(),originUrl.Length(),0,&urlcomponents);

回答1:


You are passing originUrl.c_str() to the dwUrlLength parameter of InternetCrackUrl(). You need to pass either 0 or originUrl.length() instead. You should also be checking the return value of InternetCrackUrl() for failure.

if (!InternetCrackUrl(originUrl.c_str(),originUrl.length(),0,&urlcomponents))
{
    DWORD ErrCode - GetLastError();
    ...
}



回答2:


The Problem solved and I'm Gonna share it here :D

it's so obvious that when GetLastError returns ERROR_INSUFFICIENT_BUFFER You need to increase the Length or size of something for god sake!!! :D so, I increased it :D , ex:

urlcomponents.dwHostNameLength=1024;

cause my buffer size was

=new char [1024];

AWESOME!



来源:https://stackoverflow.com/questions/26036494/internetcrackurl-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!