地
地质灾害
Unregistered / Unconfirmed
GUEST, unregistred user!
一段调用WinInet API进行Http Post的代码 向本地的Web服务器Post成功 往外网的服务器Post就不成功 良久找不到原因。求助各位大虾。代码如下<br><br>function ParseUrl(const aUrl:string;var aHost,aFile:string;var aPort:Integer):Boolean;<br>var<br> i: Integer;<br> S:string;<br>begin<br> Result:=False;<br> if aUrl='' then Exit;<br> if FastPos('http://', LowerCase(aUrl),1) <> 0 then<br> S:=Copy(aURL, 8,Length(aUrl)-7)<br> else if FastPos('https://', LowerCase(aUrl),1) <> 0 then<br> S:=Copy(aURL, 9,Length(aUrl)-8)<br> else S:=aUrl;<br> if S='' then Exit;<br> i := FastPos('/',S,1);<br> if i=1 then Exit;<br> if i=0 then<br> begin<br> aFile:='/';<br> aHost:=S;<br> end<br> else if i=1 then Exit<br> else<br> begin<br> aHost := Copy(S, 1, i - 1);<br> aFile := Copy(S, i, Length(S) - i + 1);<br> end;<br> i := FastPos(':',aHost,1);<br> if i > 0 then<br> begin<br> if (i=1) or (i=Length(aHost)) then Exit;<br> if not StrToIntDef(Copy(aHost, i + 1, Length(aHost) - i),aPort) then Exit;<br> Delete(aHost, i, Length(aHost)-i+1);<br> end<br> else aPort:=80;<br> if (aHost[Length(aHost)] = '/') then<br> Delete(aHost, Length(aHost),1);<br> Result:=True;<br>end;<br><br>function IntToStr(Value: Integer): string;<br>asm<br> PUSH ESI<br> MOV ESI, ESP<br> SUB ESP, 16<br> XOR ECX, ECX <br> PUSH EDX<br> XOR EDX, EDX<br> CALL CvtInt<br> MOV EDX, ESI<br> POP EAX<br> CALL System.@LStrFromPCharLen<br> ADD ESP, 16<br> POP ESI<br>end;<br><br>procedure UrlHttpPost(aUrl:string;aPostData:string);<br>var<br> aHost,aFile:string;<br> aPort:Integer;<br> hSession,hConnection,hRequest: HINTERNET;<br> mimeTypeAnsiChar;<br>begin<br> if not ParseUrl(aUrl,aHost,aFile,aPort) then Exit;<br> hSession:=InternetOpen(nil,INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);<br> if hSession=nil then<br> begin<br> Exit;<br> end;<br> hConnection:=InternetConnect(hSession,PChar(aHost),aPort,nil,nil,INTERNET_SERVICE_HTTP,0,0);<br> if hConnection=nil then<br> begin<br> InternetCloseHandle(hSession);<br> Exit;<br> end;<br> mimeType:='Accept: *.*';<br> hRequest:=HttpOpenRequest(hConnection,'POST',PChar(aFile),'HTTP/1.1',nil,@mimeType,INTERNET_FLAG_RELOAD,0);<br> if hRequest=nil then<br> begin<br> InternetCloseHandle(hConnection);<br> InternetCloseHandle(hSession);<br> Exit;<br> end;<br> if HttpSendRequest(hRequest,'Content-Type: application/x-www-form-urlencoded',47,PAnsiChar(aPostData),Length(aPostData)) then<br> begin<br> InternetCloseHandle(hRequest);<br> InternetCloseHandle(hConnection);<br> InternetCloseHandle(hSession);<br> end;<br>end;