代码之家  ›  专栏  ›  技术社区  ›  Rajaraman Subramanian

在Windows Mobile中设置HTTP POST参数

  •  2
  • Rajaraman Subramanian  · 技术社区  · 15 年前

    这里srequeseheaders是Unicode格式的头文件,MSDN文档说明了以下关于用于POST参数的lpOptional参数

    人口[英寸]

    指向缓冲区的指针,该缓冲区包含在请求头之后立即发送的任何可选数据。此参数通常用于POST和PUT操作。可选数据可以是发布到服务器的资源或信息。如果没有要发送的可选数据,则此参数可以为NULL。

    它只是说,pOptional是一个包含可选数据的缓冲区,dwOptionalLength以字节为单位指定缓冲区,但是当尝试向这个调用发送Unicode缓冲区及其大小(以字节为单位)时,响应不是200(HTTP\u OK)。经过几次尝试,我发现参数必须在ANSI缓冲区中。所有其他参数都处理LPCTSTR,即TCHAR缓冲区,只有这个参数需要是ANSI缓冲区。这是密码

    if( FALSE == HttpSendRequest(hRequest, (LPCTSTR)sRequestHeaders, sRequestHeaders.GetLength(), LPVOID)(LPSTR)pszAnsiRequestParams, dwRequestParamsLen ) )
    

    在上面的调用中,pszAnsiRequestParams是ANSI buffer,dwRequestParamsLen是该缓冲区的大小(字节)。一旦我改变了这个,答案是200。你总是这样发送参数吗?如果是这种情况,我将如何发送Unicode POST参数?因为在我的情况下,我正在处理ASCII字符暂时这是工作良好,但不知何故,我觉得应该有一个出路。

    1 回复  |  直到 15 年前
        1
  •  0
  •   Abhijeet Kashnia    15 年前

    我不确定编码部分,但如果您只关心发送POST参数,这里有另一种方法。我使用HttpWebRequest发送post参数。这里有一个片段。

    HttpWebRequest webRequest;
    webRequest.Method = "POST";
    webRequest.ContentType = "application/x-www-form-urlencoded";
    
    // Prepare a requestParameterString
    private String PrepareRequestString(String requestParameterString, String requestParamName, String data)
    {
        if (!requestParameterString.Equals(String.Empty))
        {
            requestParameterString += "&";
        }
        return requestParameterString += requestParamName + "=" + data;
    }
    
    // Set the request param data.
    Stream requestStream = null;
    webRequest.ContentLength = data.Length;
    byte[] buffer = Encoding.UTF8.GetBytes(data);
    requestStream = webRequest.GetRequestStream();
    requestStream.Write(buffer, 0, buffer.Length);
    
    // Finally, make the call.
    WebResponse response = webRequest.GetResponse();
    
    推荐文章