虽然下载有效,但发帖请求无效(Chilkat)

时间:2019-04-16 15:04:05

标签: vb.net http post chilkat

我面临着一个非常棘手的问题,经过了很多小时才找到问题,但没有任何运气:(

我已经在移动设备(android)上设置了Web服务器。

并尝试通过我的vb应用程序使用它

我在非常简单的示例网址(相同的ip /端口)上简单地调用Download方法,它可以工作并将响应正文保存为下载文件。

但是当我尝试发送post命令时,它不起作用,它给出错误“连接被拒绝”

这是要下载的代码:

objDHTTP.Download("http://192.168.1.101:8000/fileAdmin.php", strAppDir & "\wtf-response.txt")

这是我尝试使用相同的URL和端口进行邮寄请求的代码:

objDRequest.Path = "/fileAdmin.php"
objDRequest.AddParam("fileAction", "Upload")
objDRequest.AddParam("fileName", "DB.sql")
objDRequest.AddFileForUpload("adminFile", strAppDir & "\c.dll")
objDResponse = objDHTTP.SynchronousRequest(strServerIP, 8000, False, objDRequest)

但是它不起作用并且抛出错误

以下是成功响应(用于下载方法):

<ChilkatLog>
  <Download>
    <DllDate>Dec 21 2018</DllDate>
    <ChilkatVersion>9.5.0.76</ChilkatVersion>
    <Architecture>Little Endian; 32-bit</Architecture>
    <Language>.NET 4.0</Language>
    <VerboseLogging>0</VerboseLogging>
    <url>http://192.168.1.101:8000/fileAdmin.php</url>
    <toLocalPath>G:\wtf-sucess.txt</toLocalPath>
    <currentWorkingDir>G:\</currentWorkingDir>
    <a_httpDownload>
      <httpDownloadFile>
        <localFilePath>G:\wtf-sucess.txt</localFilePath>
        <localFileAlreadyExists>1</localFileAlreadyExists>
        <quickHttpRequest>
          <httpVerb>GET</httpVerb>
          <url>http://192.168.1.101:8000/fileAdmin.php</url>
          <openHttpConnection>
            <info>Opening connection directly to HTTP server.</info>
            <httpHostname>192.168.1.101</httpHostname>
            <httpPort>8000</httpPort>
            <tls>False</tls>
            <info>HTTP connection succeeded.</info>
          </openHttpConnection>
          <buildQuickRequest>
            <genStartLine>
              <startLine>GET /fileAdmin.php HTTP/1.1</startLine>
            </genStartLine>
            <addCookies>
              <info>Not auto-adding cookies.</info>
              <sendCookies>1</sendCookies>
              <cookieDir></cookieDir>
            </addCookies>
          </buildQuickRequest>
          <sendRequestHeader>
            <sendHeaderElapsedMs>0</sendHeaderElapsedMs>
          </sendRequestHeader>
          <statusCode>200</statusCode>
          <statusText>OK</statusText>
          <checkCloseConnection>
            <info>Response includes connection:close header (or proxy-connection:close header)</info>
          </checkCloseConnection>
        </quickHttpRequest>
        <outputLocalFileSize>26</outputLocalFileSize>
        <numOutputBytesWritten>26</numOutputBytesWritten>
      </httpDownloadFile>
    </a_httpDownload>
    <totalElapsedMs>47</totalElapsedMs>
    <ContentLength>0</ContentLength>
    <info>Success.</info>
  </Download>
</ChilkatLog>

以下是错误/失败响应(用于发帖请求):

<ChilkatLog>
  <SynchronousRequest>
    <DllDate>Dec 21 2018</DllDate>
    <ChilkatVersion>9.5.0.76</ChilkatVersion>
    <Architecture>Little Endian; 32-bit</Architecture>
    <Language>.NET 4.0</Language>
    <VerboseLogging>0</VerboseLogging>
    <domain>191.168.1.101</domain>
    <port>8000</port>
    <ssl>0</ssl>
    <httpRequest>
      <httpVersion>1.1</httpVersion>
      <verb>POST</verb>
      <path>/fileAdmin.php</path>
      <contentType>multipart/form-data</contentType>
      <charset>windows-1252</charset>
      <sendCharset>0</sendCharset>
      <mimeHeader></mimeHeader>
      <requestParams>
        <requestItem>
          <name>fileAction</name>
          <value>Upload</value>
        </requestItem>
        <requestItem>
          <name>fileName</name>
          <value>DB.sql</value>
        </requestItem>
        <requestItem>
          <name>adminFile</name>
          <fileOnDisk>G:\c.dll</fileOnDisk>
          <numValueBytes>8697</numValueBytes>
        </requestItem>
      </requestParams>
    </httpRequest>
    <fullRequest>
      <a_synchronousRequest>
        <generateRequestHeader>
          <httpRequestGenStartLine>
            <genStartLine>
              <startLine>POST /fileAdmin.php HTTP/1.1</startLine>
            </genStartLine>
          </httpRequestGenStartLine>
          <addCookies>
            <info>Not auto-adding cookies.</info>
            <sendCookies>1</sendCookies>
            <cookieDir></cookieDir>
          </addCookies>
          <genMultipartFormData>
            <requestParam>
              <name>fileAction</name>
            </requestParam>
            <requestParam>
              <name>fileName</name>
            </requestParam>
            <requestParam>
              <name>adminFile</name>
              <filename>G:\c.dll</filename>
            </requestParam>
          </genMultipartFormData>
        </generateRequestHeader>
        <fullHttpRequest>
          <domain>191.168.1.101</domain>
          <port>8000</port>
          <ssl>0</ssl>
          <openHttpConnection>
            <info>Opening connection directly to HTTP server.</info>
            <httpHostname>191.168.1.101</httpHostname>
            <httpPort>8000</httpPort>
            <tls>False</tls>
            <socket2Connect>
              <connect2>
                <connectSocket>
                  <connect_ipv6_or_ipv4>
                    <info>Connection attempt failed.</info>
                    <maxWaitTimeMs>10000</maxWaitTimeMs>
                    <totalMsWaitedSoFar>2100</totalMsWaitedSoFar>
                  </connect_ipv6_or_ipv4>
                  <connect_ipv6_or_ipv4>
                    <info>Connection attempt failed.</info>
                    <maxWaitTimeMs>10000</maxWaitTimeMs>
                    <totalMsWaitedSoFar>2150</totalMsWaitedSoFar>
                  </connect_ipv6_or_ipv4>
                </connectSocket>
                <ConnectFailReason>Connection rejected</ConnectFailReason>
                <error>A few possible causes for a connection being rejected are:</error>
                <error>- A firewall (software or hardware), such as Windows Firewall, is blocking the connection .</error>
                <error>- Nothing is listening at the remote host:port</error>
              </connect2>
            </socket2Connect>
          </openHttpConnection>
        </fullHttpRequest>
        <success>0</success>
      </a_synchronousRequest>
      <success>0</success>
    </fullRequest>
    <totalTime>Elapsed time: 4390 millisec</totalTime>
    <error>Failed.</error>
  </SynchronousRequest>
</ChilkatLog>

有人可以告诉我这是什么原因吗?

预先感谢

最好的问候

1 个答案:

答案 0 :(得分:0)

LastErrorText中可能存在原因:

            <ConnectFailReason>Connection rejected</ConnectFailReason>
            <error>A few possible causes for a connection being rejected are:</error>
            <error>- A firewall (software or hardware), such as Windows Firewall, is blocking the connection .</error>
            <error>- Nothing is listening at the remote host:port</error>

我的猜测是Windows防火墙阻止了出站POST。

此示例显示了由于各种TCP套接字连接问题而将导致的错误:https://www.example-code.com/vbnet/socket_connect_fail.asp