我正在尝试将音频文件发布到我的Web服务并从服务器获取响应。我在Google上搜索但没有Windows Phone 8的答案。所以请帮助我。
更新1这里我的代码尝试上传音频文件,但服务器上有错误
byte[] buffer;
void Upload(Stream fileStream)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://localhost:11111/api/SpeechRecognition?dataType=json"));
request.Method = "POST";
request.ContentType = "multipart/form-data";
request.UseDefaultCredentials = true;
buffer = new byte[(int)fileStream.Length];
request.BeginGetRequestStream(new AsyncCallback(ReadCallback), request);
}
private void ReadCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation.
Stream postStream = request.EndGetRequestStream(asynchronousResult);
postStream.Write(buffer, 0, buffer.Length);
postStream.Close();
request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
}
private void ResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse resp = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = resp.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
Dispatcher.BeginInvoke(new Action(() => { MessageBox.Show(responseString); }));
// Close the stream object.
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse.
resp.Close();
}
在服务器ASP.NET 4.5中有错误行
await Request.Content.ReadAsMultipartAsync(provider);