发送POST请求到Microsoft Web浏览器 [英] send POST request to Microsoft web browser

查看:101
本文介绍了发送POST请求到Microsoft Web浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我有一个问题,我不能解决2天. :((

我需要在POST请求中发送数据:
1.到Microsoft Web浏览器
2.至系统默认浏览器

请帮助我:信息,代码行等等.谢谢!

Hi guys! I have a problem, which I can''t solve 2 day. :((

I need to send data in POST request:
1. to Microsoft Web browser
2. to system default browser

Help me, please: info, code line, whatever. Thanx!

推荐答案

要创建POST请求,您必须使用HTTPWebRequest类. Request方法必须设置为POST.您必须定义内容类型(文本,xml或基于您的要求的任何内容),最后将需要发送到服务器的数据写入Request对象的流中.
请参考下面的代码-

您必须在str字符串中将要发送的数据写入POST请求的消息正文中.根据您的需要,它可以是c#类,也可以是简单的字符串,以&"分隔.

To create a POST request you have to use the HTTPWebRequest class. The Request method has to be set to POST. You have to define the content type (text, xml or anything based on your requirement) and finally write the data that you need to send to the server in the stream of the Request object.
Refer the code below -

You have to write your data that you need to send in the message body of your POST request in the str string. This can be c# class, or simple string separated by ''&'' as per your need.

// Convert string data into byte array 
byte[] dataByte = Encoding.UTF8.GetBytes(strData);
            
            HttpWebRequest POSTRequest = (HttpWebRequest)WebRequest.Create(strURL);
            POSTRequest.Method = "POST";
// Set the content type - Mine was xml.
            POSTRequest.ContentType = "text/xml";
            POSTRequest.KeepAlive = false;
            POSTRequest.Timeout = 5000;
            POSTRequest.ContentLength = dataByte.Length;
// Get the request stream
            Stream POSTstream = POSTRequest.GetRequestStream();
            // Write the data bytes in the request stream
            POSTstream.Write(dataByte, 0, dataByte.Length); 

//Get response from server
            HttpWebResponse POSTResponse = (HttpWebResponse)POSTRequest.GetResponse();



希望这对您有帮助



Hope this helps


这里的教程可能会有所帮助:

W3Schools表单课程 [
Here''s a tutorial that might help:

W3Schools Forms Lesson[^]. The POST method isn''t defined by Microsoft; it''s a universal standard and works the same in any browser. Browsers POST data to servers, and servers reply with a new page. The POST method of passing data is more secure than GET, and doesn''t have the length limitation of a GET. Spend an hour reading and you''ll find that it''s easier than it first sounds. Good luck! :-D


这篇关于发送POST请求到Microsoft Web浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆