首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(0) | 引用(0) | 阅读1281次
HttpWebRequest WebResponse PROXY URLENCODE 2 代码

HttpWebRequest WebResponse PROXY URLENCODE 2 代码

HttpWebRequest WebResponse PROXY URLENCODE 1
http://www.shengfang.org/blog/p/HttpWebReqRespPROXYURLENC1.php

模拟提交:
private void baidu_Click(object sender, System.EventArgs e)
{
getPage("http://www.shengfang.org/blog/index.php", "job=showsearch&keywords=mysql");
}

public static void getPage(String url, String payload)
{
 WebResponse result = null; www.shengfang.org

 try
 { www.shengfang.org

  HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
  req.Method = "POST"; www.shengfang.org
  req.ContentType = "application/x-www-form-urlencoded";
  req.Accept ="image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
  StringBuilder UrlEncoded = new StringBuilder();
  Char[] reserved = { '?', '=', '&' };
  byte[] SomeBytes = null;

  if (payload != null)
  {
   int i=0, j;
   while(i<payload.Length)
   {
    j=payload.IndexOfAny(reserved, i);
    if (j==-1) www.shengfang.org
    {
     UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, payload.Length-i)));
     break;
     }
    UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, j-i)));
    UrlEncoded.Append(payload.Substring(j,1));
    i = j+1;
    }
   Trace.WriteLine(UrlEncoded.ToString());
   SomeBytes = Encoding.Default.GetBytes(UrlEncoded.ToString());
   SomeBytes = Encoding.Default.GetBytes( "stext=%CA%A2%B7%C5&imageField.x=22&imageField.y=7");
   //SomeBytes = Encoding.UTF8.GetBytes("s?wd=%CA%A2%B7%C5&cl=3");
   req.ContentLength = SomeBytes.Length;
   Stream newStream = req.GetRequestStream();
   newStream.Write(SomeBytes, 0, SomeBytes.Length);
   newStream.Close();
   }
  else  www.shengfang.org
  {
   req.ContentLength = 0;
   }

www.shengfang.org
  result = req.GetResponse();
  Stream ReceiveStream = result.GetResponseStream();
  Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
  StreamReader sr = new StreamReader( ReceiveStream, System.Text.Encoding.Default  );
  Trace.WriteLine("\r\n已接收到响应流");
  Char[] read = new Char[256];
  int count = sr.Read( read, 0, 256 );
  Trace.WriteLine("HTML...\r\n");
  while (count > 0)
  {
   String str = new String(read, 0, count);
   Trace.Write(str);
   count = sr.Read(read, 0, 256);
   }
  Trace.WriteLine("");
  }
 catch(Exception e)  www.shengfang.org
 {
  Trace.WriteLine( e.ToString());
  Trace.WriteLine("\r\n找不到请求 URI,或者它的格式不正确");
  }
 finally
 {
  if ( result != null )
  {
   result.Close();
   }
  }
} www.shengfang.org


字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/HttpWebReqRespPROXYURLENC2.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1134360607

2005年12月12日12:10星期一  [Dev开发] 追踪此文的RSS
提示:
此文还没有评论。

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1967
在线: 19||用户: 2593 [列表]
今日:932||到访:3118103
Rss:||评论:1631

最新日志

最新评论

友情链接

日历
2008 - 11
      1
2345678
9101112131415
16171819202122
23242526272829
30      

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8