简体   繁体   English

C#HttpRequest发布URL

[英]C# HttpRequest posting a URL

I'm trying to get an HttpRequest to post this URL 我正在尝试获取一个HttpRequest来发布此URL

https://www.iformbuilder.com/exzact/_emptyTable.php?PAGE_ID=1234&TABLE_NAME=table_name_here&USERNAME=yo@yo.com&PASSWORD=What!What ! https://www.iformbuilder.com/exzact/_emptyTable.php?PAGE_ID=1234&TABLE_NAME=table_name_here&USERNAME=yo@yo.com&PASSWORD=什么 !什么!

I've tried using 我试过使用

WebClient rar = new WebClient();
rar.OpenReadAsync(new Uri(@"https://www.iformbuilder.com/exzact/_emptyTable.php?PAGE_ID=1234&TABLE_NAME=table_name_here&USERNAME=yo@yo.com&PASSWORD=What!What!"));

rar.DownloadStringAsync(new Uri(@"https://www.iformbuilder.com/exzact/_emptyTable.php?PAGE_ID=1234&TABLE_NAME=table_name_here&USERNAME=yo@yo.com&PASSWORD=What!What!"));

This is suppose to delete my information on their site, but it's not taking. 这样做是为了删除我在他们网站上的信息,但没有采取。 i'm following this documentation. 我正在遵循此文档。 http://getsatisfaction.com/exzact/topics/how_can_we_delete_old_records_not_manually http://getsatisfaction.com/exzact/topics/how_can_we_delete_old_records_not_manually

and they state that all I have to do is paste the proper URL into a web browser and hit enter and it will work. 他们说,我要做的就是将正确的URL粘贴到Web浏览器中,然后按Enter键,它将起作用。 How would I do this equivalent in c#? 我将如何在C#中做到这一点? Any help would be awesome! 任何帮助都是极好的! Thanks! 谢谢!

Use WebClient.DownloadString instead of DownloadStringAsync. 使用WebClient.DownloadString而不是DownloadStringAsync。 Async indicates asynchronous methods that do not block the current thread. 异步表示不阻塞当前线程的异步方法。

Try setting your User-Agent header in your WebClient before you submit it to see if that fixes things. 提交之前,请尝试在WebClient中设置User-Agent标头,以查看是否可以解决问题。

rar.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")

A lot of web servers are set up to simply ignore requests if the User-Agent header is missing. 如果缺少User-Agent标头,则将许多Web服务器设置为仅忽略请求。

Subsequently, you're using HTTPS here so you'll want to set up your ServicePointManager.ServerCertificateValidationCallback as well. 随后,您在这里使用HTTPS,因此您还需要设置ServicePointManager.ServerCertificateValidationCallback

Try to use System.Web classes, for example like this: 尝试使用System.Web类,例如:

        HttpWebRequest req = null;
        HttpWebResponse resp = null;

        try
        {
            req = (HttpWebRequest)HttpWebRequest.Create(url); // enter your url

            req.Method = "post";

            resp = (HttpWebResponse)req.GetResponse();
        }
        catch (Exception)
        {
            throw;
        }

It's example for post method, you can use any other HTTP method like this. 这是post方法的示例,您可以使用其他任何HTTP方法。 Check the documentation . 检查文档

这不是您问题的直接答案,但请查看Hammock for REST

  string uriString = @"https://www.iformbuilder.com/exzact/_emptyTable.php?PAGE_ID=1234&TABLE_NAME=table_name_here&USERNAME=yo@yo.com&PASSWORD=What!What!"; using (WebClient webClient = new WebClient { Encoding = Encoding.UTF8 }) { try { string content = webClient.DownloadString(uriString); //do stuff with the answer you got back from the site } catch (Exception exception) { //handle exceptions } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM