0

I need to extract data from an URL which returns HTML data. I can do it using Postman I just need the correct syntax to do it in ASP.NET MVC C#.

https://www.dsebd.org/ajax/load-news.php

Headers

accept:text/html, */*; q=0.01
accept-language:en-US,en;q=0.9
content-type:application/x-www-form-urlencoded; charset=UTF-8
sec-fetch-dest:empty
sec-fetch-mode:cors
sec-fetch-site:same-origin
x-requested-with:XMLHttpRequest

And the method is Post.

Can anyone please share me the syntax in ASP.NET MVC C#?

8
  • What's the data you are getting in postman? Commented Oct 28, 2020 at 6:09
  • @ChetanRanpariya The data returns an HTML table Commented Oct 28, 2020 at 6:24
  • 1
    Will this help stackoverflow.com/questions/26002778/… Commented Oct 28, 2020 at 6:41
  • And This stackoverflow.com/questions/16642196/… Commented Oct 28, 2020 at 6:43
  • 2
    @Abdullah-Al-Nahian Glad to hear you have fixed the problem. According to your question title and the description "How to get data from this URL", it seems that you want to get the response headers from the response, instead of adding all the headers in the request. If you change the question to "how to add headers in http request", it might be easier for us to understand what you want. Commented Oct 28, 2020 at 7:43

1 Answer 1

1

Guys I wanted the correct format. I never asked for the rules of web scraping.

var httpWebRequest = (HttpWebRequest)WebRequest.Create(String.Format(url));
            httpWebRequest.Accept = "text/html, */*; q=0.01";
            httpWebRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
            httpWebRequest.Headers.Add("accept-language", "en-US,en;q=0.9");
            httpWebRequest.Headers.Add("sec-fetch-dest", "empty");
            httpWebRequest.Headers.Add("sec-fetch-mode", "cors");
            httpWebRequest.Headers.Add("sec-fetch-site", "same-origin");
            httpWebRequest.Headers.Add("x-requested-with", "XMLHttpRequest");
            httpWebRequest.Method = "POST";

This is all I asked. Thanks for your help though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.