如何使用C#将文本从Windows应用程序传递到网页 [英] How to pass text from windows application to web page using c#

查看:73
本文介绍了如何使用C#将文本从Windows应用程序传递到网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我正在Windows应用程序上工作,我需要将Windows应用程序上生成的错误传递给网站.我认为Get/Post方法是有效的解决方案.
我需要帮助.
任何形式的链接,建议和特别的专家建议都将受到高度赞赏.


谢谢与问候,
Balkrishna Raut

Dear all,
I am working on windows application and i need to pass errors generated on a windows application to web site. i think Get/Post method is valid solution.
i need a help.
Any kind of link, suggestion and specially expert advice would be highly appreciated.


Thanks & Regards,
Balkrishna Raut

推荐答案


您可以通过发布参数发送错误:

Hi,
you can send the errors via post parameters:

string HttpPost (string uri, string parameters)
{ 
   // parameters: name1=value1&name2=value2	
   WebRequest webRequest = WebRequest.Create (uri);
   webRequest.ContentType = "application/x-www-form-urlencoded";
   webRequest.Method = "POST";
   byte[] bytes = Encoding.ASCII.GetBytes (parameters);
   Stream os = null;
   try
   { // send the Post
      webRequest.ContentLength = bytes.Length;   
      os = webRequest.GetRequestStream();
      os.Write (bytes, 0, bytes.Length);         //Send it
   }
   catch (WebException ex)
   {
      MessageBox.Show ( ex.Message, "HttpPost: Request error", 
         MessageBoxButtons.OK, MessageBoxIcon.Error );
   }
   finally
   {
      if (os != null)
      {
         os.Close();
      }
   }
 
   try
   { // get the response
      WebResponse webResponse = webRequest.GetResponse();
      if (webResponse == null) 
         { return null; }
      StreamReader sr = new StreamReader (webResponse.GetResponseStream());
      return sr.ReadToEnd ().Trim ();
   }
   catch (WebException ex)
   {
      MessageBox.Show ( ex.Message, "HttpPost: Response error", 
         MessageBoxButtons.OK, MessageBoxIcon.Error );
   }
   return null;
} // end HttpPost 



...

在Web应用程序中,访问Request.Form以读取参数:



...

In the web application access Request.Form to read the parameters:

NameValueCollection nvc = Request.Form;
var p = nvc["Your parameter name"]



问候



Regards


请检查以下线程:

http://forums.asp.net/t/1223016.aspx [
Please check the following thread:

http://forums.asp.net/t/1223016.aspx[^]


这篇关于如何使用C#将文本从Windows应用程序传递到网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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