本文整理汇总了C#中WebRequest.GetResponse方法的典型用法代码示例。如果您正苦于以下问题:C# WebRequest.GetResponse方法的具体用法?C# WebRequest.GetResponse怎么用?C# WebRequest.GetResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebRequest
的用法示例。
在下文中一共展示了WebRequest.GetResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixedUpdate
void FixedUpdate()
{
Debug.Log("sending HTTP request! to:");
Debug.Log(url);
mycoord = WebRequest.Create(url);
Stream objStream;
objStream = mycoord.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
sLine = objReader.ReadLine ();
Debug.Log("Got response!");
if(sLine.Length > 4) {
coordinates = sLine;
}
Debug.Log(coordinates);
int x = System.Convert.ToInt32 (coordinates [1]);
int y = System.Convert.ToInt32 (coordinates [3]);
float newX = 0 + (x * 2);
newX -= 96; //for some reason unity jumps my cardboard main to 96,-96
float newZ = 0 - (y * 2);
newZ += 96;
transform.position = new Vector3(newX, 1.5f,newZ);
}
示例2: SendPostRequest
/// <summary>
/// Send a simple Post request
/// </summary>
/// <param name="ip">IP of client</param>
/// <returns></returns>
/// <remarks>Used port 80</remarks>
public static string SendPostRequest(string ip)
{
WebRequest webRequest = new WebRequest(ip, "POST");
var response = webRequest.GetResponse();
return response;
}
示例3: GetHttpWebResponse
protected static string GetHttpWebResponse(WebRequest webRequest)
{
StreamReader responseReader = null;
string responseData;
try
{
responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
responseData = responseReader.ReadToEnd();
}
finally
{
webRequest.GetResponse().GetResponseStream().Close();
responseReader.Close();
}
return responseData;
}
示例4: ReadResponse
private string ReadResponse(WebRequest request)
{
using (var responseStream = request.GetResponse().GetResponseStream())
{
using (var respReader = new StreamReader(responseStream))
{
return respReader.ReadLine();
}
}
}
示例5: GetResponseAsync
public override Task<WebResponse> GetResponseAsync(WebRequest request) => Task.Run(() => request.GetResponse());
示例6: GetWebReponseLogErrors
/// <summary>
/// Get the web response; log any error codes that occur and rethrow the exception.
/// This allows us to get error log data with detailed information
/// </summary>
/// <param name="webRequest"></param>
/// <returns></returns>
protected WebResponse GetWebReponseLogErrors(WebRequest webRequest, string description)
{
string requestUri = webRequest.RequestUri.ToString();
try
{
return webRequest.GetResponse();
}
catch (WebException webException)
{
AttemptToLogWebException(webException, description + " (" + requestUri + ") ", this.StatusLog);
throw webException;
}
}
示例7: requestString
public string requestString (WebRequest wb)
{
WebResponse webResponse = wb.GetResponse ();
StreamReader reader = new StreamReader (webResponse.GetResponseStream ());
string response = reader.ReadToEnd ();
reader.Close ();
webResponse.Close ();
return response;
}
示例8: Ping
public bool Ping(string osVersion, string cjVersion, string machineID)
{
requestPingAborting = false;
// Create a request using a URL that can receive a post.
requestPing = WebRequest.Create (serverUrl + "/ping");
// Set the Method property of the request to POST.
requestPing.Method = "POST";
// Set the ContentType property of the WebRequest.
requestPing.ContentType = "application/json";
// Creates the json object
JsonObject json = new JsonObject();
json.Add("os_version", osVersion);
json.Add("cj_version", cjVersion);
json.Add("machine_id", machineID);
// Converts it to a String
String js = json.ToString();
// Writes the json object into the request dataStream
Stream dataStream;
try {
dataStream = requestPing.GetRequestStream ();
} catch {
this.ResultMessage =
string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."),
serverUrl);
return false;
}
if(requestPingAborting) {
LogB.Information("Aborted from PingAbort");
return false;
}
dataStream.Write (Encoding.UTF8.GetBytes(js), 0, js.Length);
dataStream.Close ();
// Get the response.
WebResponse response;
try {
response = requestPing.GetResponse ();
} catch {
this.ResultMessage =
string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."),
serverUrl);
return false;
}
if(requestPingAborting) {
LogB.Information("Aborted from PingAbort");
return false;
}
// Display the status (will be 201, CREATED)
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Clean up the streams.
dataStream.Close ();
response.Close ();
this.ResultMessage = "Ping sent.";
return true;
}