猿问
下载APP

请问这个cookiecollection该怎么转换成字符?

cookiecollection怎么转换成字符


慕雪6442864
浏览 44回答 4
4回答

慕勒3428872

using System.Net;using System.IO;using System.Text;class Test{[STAThread]static void Main(string[] args){//// TODO: 在此处添加代码以启动应用程序//string url = "http://localhost/csdn2/1.asp";// <%// if request("aa")="zhuye" then session("ok")="ok"// if session("ok")="ok" then// response.write("登录")// else// response.write("没有登录")// end if// %>string indata = "aa=zhuye";string outdata = "";CookieContainer myCookieContainer = new CookieContainer();//新建一个CookieContainer来存放Cookie集合HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);//新建一个HttpWebRequestmyHttpWebRequest.ContentType = "application/x-www-form-urlencoded";myHttpWebRequest.ContentLength = indata.Length;myHttpWebRequest.Method = "POST";myHttpWebRequest.CookieContainer = myCookieContainer;//设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainerStream myRequestStream = myHttpWebRequest.GetRequestStream();StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));myStreamWriter.Write(indata);//把数据写入HttpWebRequest的Request流myStreamWriter.Close();myRequestStream.Close();//关闭打开对象HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();//新建一个HttpWebResponsemyHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);//获取一个包含url的Cookie集合的CookieCollectionStream myResponseStream = myHttpWebResponse.GetResponseStream();StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));outdata = myStreamReader.ReadToEnd();//把数据从HttpWebResponse的Response流中读出myStreamReader.Close();myResponseStream.Close();Console.WriteLine(outdata);//显示"登录"//拿到了Cookie,再进行请求就能直接读取到登录后的内容了myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);myHttpWebRequest.CookieContainer = myCookieContainer;//*//刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);myResponseStream = myHttpWebResponse.GetResponseStream();myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));outdata = myStreamReader.ReadToEnd();myStreamReader.Close();myResponseStream.Close();Console.WriteLine(outdata);//再次显示"登录"//如果把*行注释调,就显示"没有登录"}}

jeck猫

字符串 是String类 这是一个对象字符 是char 类型,是基本类型 和编码方式有关 一般情况下不要用char 类型如果要将String类 转成 char [ ]数组,toCharArray() 可以用这个方法例如:String s="xxxxxxx"; char [ ] chArr=s.toCharArray();如果要取得String对象中某个字符 就用charAt(int index)方法例如 char ch=s.charAi(1);public class Test {public static void main(String[] args) {String s="123456";char [] charArr=s.toCharArray();for(int i=0;i<s.length();i++)System.out.printf("%4s",charArr[i]);char ch=s.charAt(5);System.out.println("\n"+ch);}}

慕村225694

代码:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System;using System.Net;using System.IO;using System.Text;class Test{[STAThread]static void Main(string[] args){//// TODO: 在此处添加代码以启动应用程序//string url = "http://localhost/csdn2/1.asp";// <%// if request("aa")="zhuye" then session("ok")="ok"// if session("ok")="ok" then// response.write("登录")// else// response.write("没有登录")// end if// %>string indata = "aa=zhuye";string outdata = "";CookieContainer myCookieContainer = new CookieContainer();//新建一个CookieContainer来存放Cookie集合HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);//新建一个HttpWebRequestmyHttpWebRequest.ContentType = "application/x-www-form-urlencoded";myHttpWebRequest.ContentLength = indata.Length;myHttpWebRequest.Method = "POST";myHttpWebRequest.CookieContainer = myCookieContainer;//设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainerStream myRequestStream = myHttpWebRequest.GetRequestStream();StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));myStreamWriter.Write(indata);//把数据写入HttpWebRequest的Request流myStreamWriter.Close();myRequestStream.Close();//关闭打开对象HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();//新建一个HttpWebResponsemyHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);//获取一个包含url的Cookie集合的CookieCollectionStream myResponseStream = myHttpWebResponse.GetResponseStream();StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));outdata = myStreamReader.ReadToEnd();//把数据从HttpWebResponse的Response流中读出myStreamReader.Close();myResponseStream.Close();Console.WriteLine(outdata);//显示"登录"//拿到了Cookie,再进行请求就能直接读取到登录后的内容了myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);myHttpWebRequest.CookieContainer = myCookieContainer;//*//刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);myResponseStream = myHttpWebResponse.GetResponseStream();myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));outdata = myStreamReader.ReadToEnd();myStreamReader.Close();myResponseStream.Close();Console.WriteLine(outdata);//再次显示"登录"//如果把*行注释调,就显示"没有登录"}}注释写得很明确了,不多罗嗦了。 补充:如果是以get方式登录的话,直接修改url就可以了,indate可以不写任何东西。(不要去修改 myHttpWebRequest.Method为GET),比如把asp文件修改为 if request.querystring("aa")="zhuye" then session("ok")="ok",只要修改url为 string url="http://localhost/csdn2/1.asp?aa=zhuye";即可。

慕仰8121524

using System.Net;using System.IO;using System.Text;class Test{[STAThread]static void Main(string[] args){//// TODO: 在此处添加代码以启动应用程序//string url = "http://localhost/csdn2/1.asp";// <%// if request("aa")="zhuye" then session("ok")="ok"// if session("ok")="ok" then// response.write("登录")// else// response.write("没有登录")// end if// %>string indata = "aa=zhuye";string outdata = "";CookieContainer myCookieContainer = new CookieContainer();//新建一个CookieContainer来存放Cookie集合HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);//新建一个HttpWebRequestmyHttpWebRequest.ContentType = "application/x-www-form-urlencoded";myHttpWebRequest.ContentLength = indata.Length;myHttpWebRequest.Method = "POST";myHttpWebRequest.CookieContainer = myCookieContainer;//设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainerStream myRequestStream = myHttpWebRequest.GetRequestStream();StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));myStreamWriter.Write(indata);//把数据写入HttpWebRequest的Request流myStreamWriter.Close();myRequestStream.Close();//关闭打开对象HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();//新建一个HttpWebResponsemyHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);//获取一个包含url的Cookie集合的CookieCollectionStream myResponseStream = myHttpWebResponse.GetResponseStream();StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));outdata = myStreamReader.ReadToEnd();//把数据从HttpWebResponse的Response流中读出myStreamReader.Close();myResponseStream.Close();Console.WriteLine(outdata);//显示"登录"//拿到了Cookie,再进行请求就能直接读取到登录后的内容了myHttpWebRequest = (HttpWebRequest) WebRequest.Create(url);myHttpWebRequest.CookieContainer = myCookieContainer;//*//刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);myResponseStream = myHttpWebResponse.GetResponseStream();myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));outdata = myStreamReader.ReadToEnd();myStreamReader.Close();myResponseStream.Close();Console.WriteLine(outdata);//再次显示"登录"//如果把*行注释调,就显示"没有登录"}}
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答