근무 게시자 요청을 VS C#에서 VS Xamarin C#으로 올바르게 이전하는 방법을 알려주거나 "Waiting for Activation"메시지를 보내지 마십시오.선량자가 작업 요청을 VS C#에서 VS Xamarin C#으로 올바르게 마이그레이션하는 방법은 무엇입니까?
제발, 내가 얻을 수있는 도움을 사용할 수 있습니다. 나는 마녀와 관련된 예제를 손에 들고 보는 동안 나는 가장 잘 배웁니다. 또한 여기서 대부분의 예제를 따르는 데 어려움이있는 이유이기도합니다. 지금 코드는 Id = 10, Status = WaitingForActivation, Method = "{null}", Result = "{아직 계산되지 않은}"문자열 만 돌려줍니다.
먼저, 나는 Xamarin으로 나중에 마이그레이션하고 싶었던 프로그램의 원형을 만들었다. 그 당시에 저는 Xamarin으로 바로 뛰어들 수있는 자원이 없었기 때문입니다.
이제 리소스가 있지만 Xamarin Framework 이해가 부족합니다. 이것은 Xamarin에서의 첫 번째 프로젝트이며 이전에는 결코 작업 해 본 적이 없습니다. Furtionaly, 제 문제는 지금 Xamarin의 Post Request와 관련이 있습니다. 그것은 내가 연구하는 시간을 보지 못했고 나는 아직도 학습하고있는 것이 아닙니다. 하지만 여전히 HttpRequestMessages.content 또는 HttpClient의 게시물 요청을 설정하는 것을 아직 이해하지 못했습니다. Hier 먼저 origgenal VS C# verssion, 내가 VS C#에있는 솔루션을 보여줍니다.
public string SendAndRecive(byte[] postData, string endPoint)
{
string strResponseValue = string.Empty;
// Sending the request
// Knocking on the door
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
// Declaring the packaged
request.ContentLength = postData.Length;
// Handing over the package
using (var stream = request.GetRequestStream())
{
stream.Write(postData, 0, postData.Length);
} // end of StreamWrite
// Asking for receipt
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
// Checking status
if (response.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException("error code: " + response.StatusCode.ToString() + response.ToString());
} // end of if
// Reciving and catching data
using (Stream responseStream = response.GetResponseStream())
{
if (responseStream != null)
{
using(StreamReader reader = new StreamReader(responseStream))
{
strResponseValue = reader.ReadToEnd();
} // end of StreamReader
} // end of if
} // end of responseStream
} // end of response
return strResponseValue;
} // end of send and recive
이것은 몇 가지 예제를 단계별로 따라 가면서 작성한 것입니다. 원본을 분리하면서 단계적으로 진행하십시오. HttpRequestMessage.Content를 설정하는 방법을 잘 모르기 때문에 미리 코딩하는 대신 메서드에 내용 코딩을 사용했습니다.
public async Task<dynamic> SendAndReciveAsync(string PostData, string EndPoint)
{
HttpRequestMessage request = new HttpRequestMessage();
request.RequestUri = new Uri(EndPoint);
request.Method = HttpMethod.Post;
byte[] Data = Encoding.UTF8.GetBytes(PostData);
ByteArrayContent Content = new ByteArrayContent(Data, 0, Data.Length);
request.Content = Content;
HttpResponseMessage response = new HttpResponseMessage();
using (var client = new HttpClient())
{
response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
}
string recivedContent = await response.Content.ReadAsStringAsync();
return await Task.Run(() => JsonConvert.DeserializeObject(recivedContent));
}
문제와 시간에 감사드립니다. 먼저 도움을 청할 때까지이 내용을 읽으십시오. 고맙습니다.