如何使用SSL进行HttpWebRequest [英] How to use SSL for HttpWebRequest

查看:68
本文介绍了如何使用SSL进行HttpWebRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我需要使用 HttpWebRequest

 

我如何才能实现它?

 

请帮我处理代码或使用适当的文章,包括VB.Net或C#中的代码

 

问候,

Shaju

推荐答案

使用以https开头的网址。

Use a URL that starts with https.

将单个字符串发送到网址的最简单方法是使用WebClient:

The easiest way to send a single string to a URL is to use WebClient:

            using (WebClient wc = new WebClient())
            {
                wc.UploadString("https://url", "Your string here");
            }

以下显示HttpWebRequest:

The following shows HttpWebRequest:

           HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://url");
            req.Method = "POST";
            req.ContentType = "text/plain; charset=UTF-8";
            using (Stream st = req.GetRequestStream())
            {
                using (StreamWriter sw = new StreamWriter(st,new UTF8Encoding(false)))
                {
                    sw.Write("Your string here.");
                }
            }
            using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse())
            {
                // Code to process response here, if any.
            }


这篇关于如何使用SSL进行HttpWebRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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