-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebScraperController.cs
More file actions
70 lines (55 loc) · 1.76 KB
/
Copy pathWebScraperController.cs
File metadata and controls
70 lines (55 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using web_scrapper.Models;
namespace web_scrapper.Controllers
{
[Route("[controller]")]
[ApiController]
public class WebScraperController : ControllerBase
{
[EnableCors("AllowOrigin")]
//[HttpGet("get")]
public async Task<IActionResult> Get(string url = "")
{
Response.Headers.Add("Access-Control-Allow-Origin", "*");
Response.Headers.Add("Access-Control-Allow-Credentials", "true");
WebScraperModel model = null;
Response response = new Response(model, "Success", false);
try
{
response.Data = await WebScraperModel.GET(url);
if (response.Data == null)
{
response.Message = "Invalid URL";
response.Error = true;
return NotFound(response);
}
}
catch (Exception ex)
{
return BadRequest(ex);
}
return Ok(response);
}
//[EnableCors("AllowOrigin")]
//public IActionResult Get()
//{
// return Ok(new Response(null, "Welcome to the Sraper API", false));
//}
}
public class Response
{
public bool Error { get; set; }
public object Data { get; set; }
public string Message { get; set; }
public Response(object data, string msj, bool error)
{
this.Error = error;
this.Message = msj;
this.Data = data;
}
}
}