using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Net ;
using System.IO ;
using System.Text ;
using System.Text.RegularExpressions;
using System.Web ;namespace WindowsApplication5
{
public class Post
{
public static void Main(string [] args)
{
Post zhucheng=new Post();
zhucheng.zhuchengxu(); }
public void zhuchengxu()
{
try
{
ASCIIEncoding encoding=new ASCIIEncoding();
string postData="COMMANDID=05";
byte[] data = encoding.GetBytes(postData);
// Prepare web request
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create("http://61.156.3.58/test.jsp");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();
Stream stream=webResponse.GetResponseStream();
System.IO.StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("GB2312"));
string content = streamReader.ReadToEnd();
// 关闭相关对象
streamReader.Close();
webResponse.Close();
}
catch(Exception ed )
{
Console.WriteLine ( "发生" + ed.ToString()+"错误!" ) ;
}
}
}
}
程序总出错误
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Net ;
using System.IO ;
using System.Text ;
using System.Text.RegularExpressions;
using System.Web ;namespace WindowsApplication5
{
public class Post
{
public static void Main(string [] args)
{
Post zhucheng=new Post();
zhucheng.zhuchengxu(); }
public void zhuchengxu()
{
try
{
ASCIIEncoding encoding=new ASCIIEncoding();
string postData="COMMANDID=05";
byte[] data = encoding.GetBytes(postData);
// Prepare web request
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create("http://61.156.3.58/test.jsp");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();
Stream stream=webResponse.GetResponseStream();
System.IO.StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("GB2312"));
string content = streamReader.ReadToEnd();
// 关闭相关对象
streamReader.Close();
webResponse.Close();
}
catch(Exception ed )
{
Console.WriteLine ( "发生" + ed.ToString()+"错误!" ) ;
}
}
}
}
程序总出错误
解决方案 »
- 如何激活外部程序最大化-请教大家
- 急求助,.netSocket数据发送及接收(struct)问题......
- 请问Calendar日历控件要控制法定节假日颜色是否在OnDayRender事件里写
- 请教orm的问题!
- 怎么得到鼠标点击了WinForm的DataGrid的什么位置?多谢
- 求月均值,SQL语句.
- 关于GotDotNet.ApplicationBlocks.Data数据更新的问题
- 请问各位:怎么样用javascript取webform中的控件的ID啊??(送分80)
- 关于水晶报表
- “文档”文件夹下的\Microsoft Press\Visual CSharp Step by Step\Chapter 4\SwitchStatemen
- 載入Global出錯,請大家幫幫忙看看是怎么回事?
- 拜求如何在Socket编程中穿透防火墙(用C#语言)急!!!
改成:
HttpWebResponse webResponse = (HttpWebResponse) myRequest.GetResponse();
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.test2.cs(37,53): error CS0103: The name 'webRequest' does not exist in the
current context
这是错误提示,要学会调试的方法....
http://blog.cngator.com
用 webclient 最方便了.
string urlString="http://www.csdn.net";WebClient client=new WebClient();
NameValueCollection formVars = new NameValueCollection();formVars.Add('test1','value1');
formVars.Add('test2','value2');byte[] responseArray = this.client.UploadValues(urlString,"POST", formVars);
string strBody = Encoding.UTF8.GetString(responseArray);
csc test.cs就提示上面的错误了....
从网上搜了一些资料,不是很会啊.现在要做一个这个接口的程序,真是很费力气.
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author easecom dongyf
* @version 1.0
*/
import java.io.*;
import java.net.*;public class postdemo {
public postdemo() {
} public static void main(String[] args) { try {
URL url = new URL("http://61.156.3.58/test.jsp"); //测试url,会把您发的参数再返回
// URL url = new URL("http://61.156.3.58/SendSms"); //实际url
URLConnection connection = url.openConnection(); connection.setDoOutput(true); OutputStreamWriter out = new OutputStreamWriter(connection.
getOutputStream(), "GB2312");
out.write("COMMANDID=05&CORPID=40068887807&CPPW=passwordaftermd5&SOURCEADDRFLAG=1&PHONE=13156160733&SENDTIME=2006-10-20 17:25:00&TITLE=smstitle&CONTENT=smstest!"); out.flush();
out.close();
DataInputStream in = new DataInputStream(connection.getInputStream());
String inline = "";
while ( (inline = in.readLine()) != null) {
System.out.println(inline);
}
in.close();
}
catch (IOException ex2) {
System.out.println(" exe IOException:" + ex2.toString()); } }}
现在在比着这个 写.net程序,里边的东西不会的太多.还得读.xml的文档,现在还不会呢.具体到哪个编码也不是很清楚.我就比较纳闷为什么.net 都用accii呢.真是麻烦啊.
这个是传统 是喜欢,好习惯
HttpWebResponse httpWRP = (HttpWebResponse)httpWRQ.GetResponse();
Stream dataStream = httpWRP.GetResponseStream();
StreamReader reader = new StreamReader(dataStream, System.Text.Encoding.GetEncoding("GB2312"));
string s_HtmlData = reader.ReadToEnd();
string s_FilePathAll = @"c:\Log\LogSource1.txt";
StreamWriter swAll = File.CreateText(s_FilePathAll);
swAll.Write(s_HtmlData);
swAll.Close();另外可以去我博客看看
里面我上传了一个开发的网页抓取程序