本文整理汇总了C#中System.Net.WebClient.UploadData方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.UploadData方法的具体用法?C# System.Net.WebClient.UploadData怎么用?C# System.Net.WebClient.UploadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了System.Net.WebClient.UploadData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Console.Title = "支付回调代理服务";
WriteLog("正在启动服务 ..");
var http = new HttpListener();
http.StartListen();
WriteLog("支付回调代理服务启动完成 ..");
Console.WriteLine();
while (true)
{
WriteLog("按任意键触发一个http模拟请求 ..");
Console.ReadKey();
WriteLog("正在模拟Http请求 ..");
var httpClient = new System.Net.WebClient();
httpClient.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
var postString = "type=test&time=" + DateTime.Now.ToString(@"yyyy\/MM\/dd HH:mm:ss");
var bytes = httpClient.UploadData(AppConfig.HttpURL, "post", Encoding.UTF8.GetBytes(postString));
var response = Encoding.UTF8.GetString(bytes);
WriteLog("服务器收到参数:" + response);
WriteLog("请检查tcp客户端是否收到模拟请求的参数 ..");
}
}
示例2: RunUnitTests
async Task RunUnitTests ()
{
var tat = typeof(NUnit.Framework.TestAttribute);
var tfat = typeof(NUnit.Framework.TestFixtureAttribute);
var types = typeof (DrawingTest).Assembly.GetTypes ();
var tfts = types.Where (t => t.GetCustomAttributes (tfat, false).Length > 0);
var ngd = System.Environment.GetFolderPath (System.Environment.SpecialFolder.MyDocuments);
PlatformTest.ResultsDirectory = System.IO.Path.Combine (ngd, "TestResults");
PlatformTest.Platform = Platforms.Current;
System.IO.Directory.CreateDirectory (PlatformTest.ResultsDirectory);
// System.Environment.CurrentDirectory = PlatformTest.ResultsDirectory;
foreach (var t in tfts) {
var test = Activator.CreateInstance (t);
var ms = t.GetMethods ().Where (m => m.GetCustomAttributes (tat, true).Length > 0);
foreach (var m in ms) {
try {
var r = m.Invoke (test, null);
var ta = r as Task;
if (ta != null)
await ta;
} catch (Exception ex) {
Console.WriteLine (ex);
}
}
}
var client = new System.Net.WebClient ();
var pngs = System.IO.Directory.GetFiles (PlatformTest.ResultsDirectory, "*.png");
foreach (var f in pngs) {
client.UploadData ("http://10.0.1.8:1234/" + System.IO.Path.GetFileName (f), System.IO.File.ReadAllBytes (f));
}
}
示例3: _Send
public override void _Send()
{
System.Net.WebClient client = new System.Net.WebClient();
client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers
byte[] response = client.UploadData("http://192.168.2.1:9393/id0/screenshots/" + this.frame.index, "POST", Encoding.Default.GetBytes("{\"frame\": " + this.frame.index + "}"));
string s = Encoding.ASCII.GetString(response);
this._OnWorkerSuccess();
}
示例4: btnSend_Click
public void btnSend_Click(object sender, EventArgs e)
{
if (System.IO.File.Exists(_filename))
{
byte[] contents = System.IO.File.ReadAllBytes(_filename);
System.Net.WebClient wc = new System.Net.WebClient();
wc.UploadData("http://localhost:1153/WebTest/bytescout/Default.aspx", contents);
}
}
示例5: AddMenu
public static string AddMenu(string accessToken, string menu)
{
using (var wc = new System.Net.WebClient())
{
var data = Utities.GetBytesFromString(menu);
var url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken;
var res = wc.UploadData(url, data);
return Utities.GetStringFromBytes(res);
}
}
示例6: btnOK_Click
//.........这里部分代码省略.........
model.RoomImage = strRoomImage;
model.FrontImageContent = byteFrontImage;
model.BackImageContent = byteBackImage;
model.UpImageContent = byteUpImage;
model.RoomImageContent = byteRoomImage;
model.TaxObject = ConfigurationManager.AppSettings["TaxObject"].ToString();
model.EmptyCode = strEmptyCode;
#endregion
if (bll.Add(model) != "")
{
if (bll.Add(model) != "-1")
{
#region ��ӳɹ���������ͬ��
try
{
string strSql = "PT_LoadWeight '" + model.WeightCode + "','" + model.TrafficCode + "','" + model.NavicertCode + "','" + model.MarkedCardCode + "','" + model.RemoteCardCode + "',"
+ "'" + model.CollCode + "','" + model.CollName + "','" + model.CoalKindCode + "','" + model.CoalKindName + "','" + model.CarOwnerName + "',"
+ "'" + model.CarNo + "','" + model.CarType + "','" + model.LoadWeight + "','" + model.EmptyWeight + "','" + model.NetWeight + "',"
+ "'" + model.OverWeight + "','" + model.RoomCode + "','" + model.RoomName + "','" + model.BangType + "','" + model.Operator + "',"
+ "'" + model.WeightTime + "','" + model.RandomCode + "','" + model.CustomerName + "','" + model.TaxType + "','" + model.TaxObject + "',"
+ "'" + model.IsFirstSite + "','" + model.FrontImage + "','" + model.BackImage + "','" + model.UpImage + "','" + model.RoomImage + "',"
+ "null,null,null,null,'" + model.EmptyCode + "'";
mq.AddNewSqlText(mq.CheckStation + mq.Prefix + "TT_LoadWeight" + mq.Prefix + mq.AddFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + mq.Prefix + strSql);
//����ͼƬ
try
{
//����ͼƬ ����ashx���ϴ�ͼƬ
System.Net.WebClient webclient = new System.Net.WebClient();
if (byteFrontImage != null)
{
webclient.UploadData(ini.IniReadValue("PicterRoute", "PRoute")+ model.WeightCode + "&filename=1", byteFrontImage);
}
if (byteBackImage != null)
{
webclient.UploadData(ini.IniReadValue("PicterRoute", "PRoute") + model.WeightCode + "&filename=2", byteBackImage);
}
if (byteUpImage != null)
{
webclient.UploadData(ini.IniReadValue("PicterRoute", "PRoute") + model.WeightCode + "&filename=3", byteUpImage);
}
if (byteRoomImage != null)
{
webclient.UploadData(ini.IniReadValue("PicterRoute", "PRoute") + model.WeightCode + "&filename=4", byteRoomImage);
}
}
catch
{
}
/********************************************************/
//Add By ����ӭ ��BSʵʱ��ط�������Ϣ���з����س�������Ϣ
/********************************************************/
string loadMessage = model.EmptyWeight.ToString() + "," + model.LoadWeight.ToString() + "," + model.NetWeight.ToString() + "," + model.OverWeight.ToString() + "," + model.TaxAmount.ToString() + "," + model.FundAmount.ToString() + "," + model.Operator.ToString() + "," + model.WeightTime.ToString()
+ "," + model.CarNo.ToString() + "," + model.CarOwnerName.ToString() + "," + model.RoomName.ToString() + "," + model.CollName.ToString() + "," + model.CoalKindName.ToString() + "," +
model.NavicertCode.ToString() + "," + model.MarkedCardCode.ToString() + "," + model.RemoteCardCode.ToString() + "," + model.WeightCode.ToString();//������Ϣ��ʽ���ճ�����,�س�����,����,����,˰��,����,������,����ʱ��,���ƺ�,��������,��������,ú������,ú������,�˿���,��ʶ����,Զ�̿���,��������
RealTimeMonitor monitor = new RealTimeMonitor();//������Ϣ
monitor.SendLoadWeightMessage(loadMessage);
/********************************************************/
}
catch { }
#endregion
示例7: GetCcAuth
protected XmlDocument GetCcAuth(XmlDocument xDoc, string URL)
{
try
{
// get the data from the xml document into a byte stream
var bdata = System.Text.Encoding.UTF8.GetBytes(xDoc.OuterXml);
// instantiate a web client
var wc = new System.Net.WebClient();
// add appropriate headers
wc.Headers.Add("Content-Type", "text/xml");
// send data to server, and wait for a response
var bresp = wc.UploadData(URL, bdata);
// read the response
var resp = System.Text.Encoding.ASCII.GetString(bresp);
var xresp = new XmlDocument();
xresp.LoadXml(resp);
// return the xml document response from the server
return xresp;
}
catch
{
// your error handler
return null;
}
}
示例8: sendMessage
//private string timestampPrefix()
//{
// return DateTime.Now.ToString("yyyyMMddHHmmssFFFFFFF");
//}
private Message sendMessage(Message request, bool encryptMessage)
{
lock (request)
{
//TODO: learn how to use compile flags
//request.ToFile(timestampPrefix() + "_request.xml");
//calibrate
if (nextCalibrate == null || nextCalibrate < DateTime.Now)
{
request.ReplaceControlValue(Message.LibraryVersionControlValueName, InternalLibraryVersion.GetLibraryVersion().ToString());
nextCalibrate = DateTime.Now.Add(calibrateFrequency);
}
System.Net.WebClient webClient = new System.Net.WebClient();
if (accessKey != null)
webClient.QueryString[Message.AccessKeyHeaderName] = accessKey;
//set encryption is using...
Aes aes = null;
if (encryptionKey != null)
{
try
{
aes = StreamUtilities.GetAesCryptoTransform(encryptionKey, null);
}
catch (CryptographicException exception)
{
throw new Exceptions.CommunicationException("Encryption exception. Is the encryption key the right length?", exception);
}
}
//message is all ready to go.
MemoryStream outgoingStream = new MemoryStream();
Common.WriteMessageStream(outgoingStream, request, sessionKey, aes, encryptMessage);
//TODO: fix these last-minute converstions to/from arrays
byte[] responseBytes;
try
{
responseBytes = webClient.UploadData(url, outgoingStream.ToArray());
}
catch (System.Net.WebException exception)
{
throw new Exceptions.CommunicationException(exception.Message);
}
MemoryStream responseStream = StreamUtilities.ToMemoryStream(responseBytes);
Message response = responseStream.ToMessage(aes);
//update sessionKey
if (response.controlValues.ContainsKey(Message.NewSessionKeyControlValueName))
sessionKey = response.controlValues[Message.NewSessionKeyControlValueName];
//response.ToFile(timestampPrefix() + "_response.xml");
return response;
}
}