Revize d5347377
Přidáno uživatelem Eliška Mourycová před více než 3 roky(ů)
Server/ServerApp/Connection/ConnectionListener.cs | ||
---|---|---|
84 | 84 |
if (context.Request.HttpMethod == "GET") // when client says download |
85 | 85 |
{ |
86 | 86 |
Console.WriteLine("received GET request"); |
87 |
responseString = ConstructGETResponse(); |
|
87 |
|
|
88 |
string text; |
|
89 |
using (var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding)) |
|
90 |
text = reader.ReadToEnd(); |
|
91 |
string requestString = HttpUtility.UrlDecode(text); |
|
92 |
|
|
93 |
responseString = ConstructGETResponse(requestString); |
|
88 | 94 |
|
89 | 95 |
} |
90 | 96 |
else if (context.Request.HttpMethod == "POST") // when client says upload |
... | ... | |
107 | 113 |
|
108 | 114 |
|
109 | 115 |
|
110 |
|
|
111 |
|
|
112 |
//string responseString = "<HTML><BODY> Hello world!</BODY></HTML>"; |
|
113 | 116 |
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); |
114 | 117 |
|
115 | 118 |
// Get a response stream and write the response to it. |
... | ... | |
126 | 129 |
} |
127 | 130 |
|
128 | 131 |
|
129 |
private string ConstructGETResponse() |
|
132 |
private string ConstructGETResponse(string requestString)
|
|
130 | 133 |
{ |
134 |
//Console.WriteLine("Constructiing a response for GET request."); |
|
135 |
|
|
136 |
//int rand = new Random().Next(1, 10); |
|
137 |
//string msg = "This is a response from the server :) " + rand; |
|
138 |
|
|
139 |
//Response xmlResp = Response.Randomize(); |
|
140 |
//var xml = XmlCommunication.Serialize(xmlResp); |
|
141 |
|
|
142 |
//return xml; |
|
143 |
|
|
144 |
|
|
131 | 145 |
Console.WriteLine("Constructiing a response for GET request."); |
132 |
|
|
133 |
int rand = new Random().Next(1, 10); |
|
134 |
string msg = "This is a response from the server :) " + rand; |
|
146 |
Console.WriteLine("Request string: "); |
|
147 |
Console.WriteLine(requestString); |
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
// prepare the type: |
|
152 |
Request newRequest = new Request(); |
|
153 |
Request requestDeserialized = null; |
|
154 |
try |
|
155 |
{ |
|
156 |
requestDeserialized = XmlCommunication.Deserialize(newRequest, requestString); |
|
157 |
} |
|
158 |
catch |
|
159 |
{ |
|
160 |
Console.WriteLine("wrong format of request!"); |
|
161 |
|
|
162 |
// don't bother to send anything: |
|
163 |
return string.Empty; |
|
164 |
} |
|
165 |
|
|
166 |
|
|
167 |
// get the prediction from the model: |
|
168 |
Response responsePrediction = predictionController.Predict(requestDeserialized); |
|
135 | 169 |
|
136 |
Response xmlResp = Response.Randomize(); |
|
137 |
var xml = XmlCommunication.Serialize(xmlResp); |
|
138 | 170 |
|
139 |
return xml; |
|
171 |
// build the xml from the prediction: - TODO mbe an exception can happen here as well? - it shouldnt |
|
172 |
return XmlCommunication.Serialize(responsePrediction); |
|
140 | 173 |
|
141 | 174 |
|
142 | 175 |
} |
Také k dispozici: Unified diff
Re #8941. Responses to GET requests.