我正在一个可以使用自己的代码扩展其功能的应用程序中使用它。
它是用 C# 编写的。
Result()
将返回从我的 Node.js 服务器获得的答案 (FinalResponse
),我将像下面这样在应用程序中访问它,但是当我尝试使用 EchoOut() 时,会出现标题中的错误。
var returnedValue = Lib.Result();
App.EchoOut(returnedValue); // EchoOut allows you to test the function you wrote, it echoes string on the screen, but in this case, it gives an error.
错误
cannot implicitly convert type void to object
当我单独测试Lib.Result()
时,我看到应用程序正在发出请求,但我无法将返回的值分配给变量。
如何将FinalResponse
的值分配给returnedValue
变量?
我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace MainNameSpace
{
public class Lib
{
public void Result()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("192.168.1.101:8000/mytest");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader stream = new StreamReader(response.GetResponseStream());
string FinalResponse = stream.ReadToEnd();
Console.WriteLine(FinalResponse);
}
}
}