Pregunta

Estoy perplejo por qué esto no puede no parece trabajo para encontrar cualquier problema.

Este es el código.

Public Const MULTIPART_BOUNDARY = "speed"
Function getBalance() As String
Dim sEntityBody As String
Dim postBody() As Byte
Dim username As String
Dim password As String

username = CStr(frmMain.txtUser.text)
password = CStr(frmMain.txtPass.text)

sEntityBody = "--" & MULTIPART_BOUNDARY & vbCrLf
sEntityBody = sEntityBody & "Content-Disposition: form-data; name=""function""" & vbCrLf & vbCrLf & "balance" & vbCrLf
sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & vbCrLf
sEntityBody = sEntityBody & "Content-Disposition: form-data; name=""username""" & vbCrLf & vbCrLf & username & vbCrLf
sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & vbCrLf
sEntityBody = sEntityBody & "Content-Disposition: form-data; name=""password""" & vbCrLf & vbCrLf & password & vbCrLf
sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & "--" & vbCrLf

postBody = StrConv(sEntityBody, vbFromUnicode)

Dim xhr As Object
Set xhr = CreateObject("WinHttp.WinHttpRequest.5.1")
xhr.Option(WinHttpRequestOption_EnableRedirects) = False
If xhr Is Nothing Then Set xhr = CreateObject("WinHttp.WinHttpRequest")
If xhr Is Nothing Then Set xhr = CreateObject("MSXML2.ServerXMLHTTP")
If xhr Is Nothing Then Set xhr = CreateObject("Microsoft.XMLHTTP")
xhr.open "POST", "http://poster.example.com", False

xhr.setRequestHeader "User-Agent", "Alalala"
xhr.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & MULTIPART_BOUNDARY
xhr.setRequestHeader "Content-Length", Len(sEntityBody)
xhr.send "" + sEntityBody 'postBody 'URLEncode(sEntityBody)

    If xhr.Status = 200 Then
        getBalance = xhr.responseText
    Else
        frmMain.addToChatbox "Failed at getting response from blah ErrCode:" & xhr.Status
    End If
End Function

Ahora bien, esta por debajo de las obras (aunque es sólo una forma de HTML).

<form 
 method="post" 
 action="http://poster.example.com/" 
 enctype="multipart/form-data">
 <input type="hidden" name="function" value="balance">
 <input type="text"   name="username" value="blah">
 <input type="text"   name="password" value="blah">
 <input type="submit" value="Send">
</form>

Esta es una aspiración de paquetes. (Altered el anfitrión etc al ejemplo después de)

  

Post / HTTP / 1.1..User-Agent:   Alalala..Content-Type:   multipart / form-data;   boundary = speed..Content-Length:   233..Accept: / .. Anfitrión: poster.example.com..Connection:   Keep-alive ....-- speed..Content-dispostion: form-data;   name = "función" .... equilibrio ..-- speed..Content-dispostion:   formar-datos;   name = "nombre de usuario" .... bla ..-- speed..Content-dispostion:   formar-datos;   name = "contraseña" .... bla ..-- velocidad - ..

respuesta es vacío

  

HTTP / 1.1 200 OK..Date: Jue, 07 de Oct   2010 20:31:20 GMT..Server:   Apache..Content-Longitud: 0..Connection:   close..Content-Type: text / html;   charset = UTF-8 ....

P. S.> El botón con valor Enviar presentar no tiene que ser enviado así que eso no es cierto, si alguien se lo pregunta. Lo que podría ser y me he dado cuenta de que huele es que envía los datos de envío + de cabecera (datos de carga) como un paquete y Firefox / Chrome envía como 2 paquetes separados.

Gracias

¿Fue útil?

Solución

Mis deletreado- Contenido-Disposición tiene que ser Contenido-Disposición yup gracias a que he estado sufriendo durante 6? tal vez 7 horas.

resolvió finalmente

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top