C#投递到浏览器发生故障,任何想法? [英] C# Post to browser fails, any ideas?

查看:92
本文介绍了C#投递到浏览器发生故障,任何想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个快速和肮脏的应用程序,只需要很短的时间工作。我不是一个开发商,所以请不要捶我。在ASP下code正常工作(秘密信息与example.com和ABC 123取代)。

This is a quick and dirty app that only needs to work for a short period. I'm not a developer so please don't hammer me. The following code in asp works fine (secret info replaced with example.com and abc 123).

我知道下面的是非常不好的做法,但是这仅仅是出于演示的目的:

I know the below is very bad practice, but this is just for demonstration purpose:

<form method="post" action="https://example.com/asppage.aspx" id="frm_main">
<input type="hidden" name="STATE" id="STATE" value="ABC" />
<input type="hidden" name="VALIDATION" id="VALIDATION" value="123/>
<input type="submit" name="refresh_progress" value="Check Status" id="refresh_progress" /></form>

不过,在我的C#后同一code不工作:

However, the same code in my c# post doesn't work:

string PostData = "STATE=ABC&amp;VALIDATION=123";
webBrowser1.Navigate("https://example.com/asppage.aspx", "_blank", Encoding.Default.GetBytes(PostData), "Content-Type: application/x-www-form-urlencoded\n\r");

在新的浏览器窗口弹出时,其默认asppage.aspx形式没有公布它的数据。

When the new browser window pops up, its the default asppage.aspx form with no data posted to it.

任何想法我做错了吗?

推荐答案

您正在给web浏览器的HTML表单,POST数据表单字段的名称和值的序列化格式,这是你所需要的把你的导航方法。

You're giving the webBrowser the html of the form, the POST data is a serialised format of the names and values of the form fields which is what you need to put in your Navigate method.

该POSTDATA需要在格式为:

The postdata needs to be in the format:

inputname1 =值1&放大器; inputname2 =值2和放大器; inputname3 =值3

您还需要URI EN code中的字符串,包括内容类型:应用程序/ x-WWW的形式urlen codeD 作为第四个参数的方法调用。

You will also need to uri encode the string and include Content-Type: application/x-www-form-urlencoded as the fourth parameter in the method call.

这篇关于C#投递到浏览器发生故障,任何想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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