从 Windows Mobile 如何将 C# 对象发送到 http 流

发布于 2024-08-23 02:27:43 字数 131 浏览 2 评论 0原文

设想: 视窗手机 C# 紧凑型框架2.0或3.5 Protobuf 对象

我需要将一个对象发送到 http url (Post)。之后,我将等待响应并收到返回的对象的修改版本。有关如何连接到 http 流并传入序列化对象的任何输入?

Scenario:
Windows Mobile
C#
Compact framework 2.0 or 3.5
Protobuf object

I need to send an object to a http url (Post). Afterward I will wait for a response and receive a modified version of the object back. Any input on how to connect to a http stream and passing in a serialized object?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

决绝 2024-08-30 02:27:43

你的意思是这样的吗?

    private string SendData(string method, string directory, string data)
    {
        string page = string.Format("http://{0}/{1}", DeviceAddress, directory);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(page);
        request.KeepAlive = false;
        request.ProtocolVersion = HttpVersion.Version10;
        request.Method = method;

        // turn our request string into a byte stream
        byte[] postBytes;

        if(data != null)
        {
            postBytes = Encoding.UTF8.GetBytes(data);
        }
        else
        {
            postBytes = new byte[0];
        }

        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = postBytes.Length;

        Stream requestStream = request.GetRequestStream();

        // now send it
        requestStream.Write(postBytes, 0, postBytes.Length);
        requestStream.Close();

        HttpWebResponse response;

        response = (HttpWebResponse)request.GetResponse();

        return GetResponseData(response);
    }

You mean something along these lines?

    private string SendData(string method, string directory, string data)
    {
        string page = string.Format("http://{0}/{1}", DeviceAddress, directory);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(page);
        request.KeepAlive = false;
        request.ProtocolVersion = HttpVersion.Version10;
        request.Method = method;

        // turn our request string into a byte stream
        byte[] postBytes;

        if(data != null)
        {
            postBytes = Encoding.UTF8.GetBytes(data);
        }
        else
        {
            postBytes = new byte[0];
        }

        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = postBytes.Length;

        Stream requestStream = request.GetRequestStream();

        // now send it
        requestStream.Write(postBytes, 0, postBytes.Length);
        requestStream.Close();

        HttpWebResponse response;

        response = (HttpWebResponse)request.GetResponse();

        return GetResponseData(response);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文