【发布时间】:2019-05-27 18:52:17
【问题描述】:
请让我知道我需要在哪里使用 Volley 在 C# 中编写“OnResponse”。
我将代码从 Android Studio 转换为使用 Volley 库的 c#。然后我在 Xamarin 中打开代码发送请求并接收响应。我添加了 Volley Nuget 包 (Xamarin.Bindings.Volley)。 以下是转换后的 C# 的代码 sn-p。但是,该代码无法识别“OnResponse”功能。我需要一个使用 Volley 在 c# 中成功实现“OnResponse”的示例。
public void GetAndPostReqquest(string url, int requestedCode, JSONObject @object, IServerResponse jsonResponse)
{
int method = Request.equestMethodConsts.Get;
switch (requestedCode)
{
case POST:
method = Request.equestMethodConsts.Post;
break;
case PUT:
method = Request.equestMethodConsts.Put;
break;
}
if (!IsInternetAvailable())
{
jsonResponse.RequestFinishedWithError(MContext.GetString(App8.Droid.Resource.String.internet_connection_is_not_available));
return;
}
jsonResponse.RequestStarted();
JsonObjectRequest request = new JsonObjectRequest(method, url, @object, Llistener, EerrorListener) {
private void OnResponse(JSONObject response)
{
IDictionary<string, string> headers = new Dictionary<string, string>();
string credentials = UNAME + ":" + PWD;
string auth = "Basic " + Convert.ToBase64String(credentials.ToCharArray(0, credentials.Length));
headers["Authorization"] = auth;
headers["Content-Type"] = "application/json; charset=utf-8";
//return headers;
}
}
【问题讨论】:
标签: c# visual-studio xamarin xamarin.android android-volley