-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequest.cs
More file actions
68 lines (65 loc) · 2.15 KB
/
Request.cs
File metadata and controls
68 lines (65 loc) · 2.15 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
using HttpParser.Models;
using HttpWebRequestExecutor.Factories;
using HttpWebRequestExecutor.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
namespace MicroFocus_Scanner
{
class Request
{
private static IHttpWebRequestFactory Factory;
string RequestString;
Regex PlaceHolder;
public ParsedHttpRequest parsed;
public Request(string requestString, IHttpWebRequestFactory factory, string pholder)
{
Factory = factory;
RequestString = requestString;
PlaceHolder = new Regex(pholder);
}
public bool modify_request(string value)
{
//Console.Write(value);
Match matched = PlaceHolder.Match(this.RequestString);
if (matched != null)
{
StringBuilder s = new StringBuilder(this.RequestString);
s.Replace(matched.Value, value);
//Console.Write();
this.RequestString = s.ToString();
return true;
}
else
{
return false;
}
}
public string send_request()
{
try
{
this.parsed = HttpParser.Parser.ParseRawRequest(this.RequestString);
IHttpWebRequest req = Factory.BuildRequest(parsed);
IHttpWebResponse resp = req.GetResponse();
string t_o = resp.GetParsedWebResponse().ResponseText;
return t_o;
}
catch (System.Net.WebException wex)
{
string ret_s = null;
using (var stream = wex.Response.GetResponseStream())
using (var reader = new System.IO.StreamReader(stream))
{
ret_s=reader.ReadToEnd();
}
Console.WriteLine($"Web exception caught. {wex.Message}");
return ret_s;
}
}
}
}