Iam目前正在使用Windows Phone 8.1应用程序。我真的很新 我想知道如何使用windows.web.http从windows phone 8.1上传图像到webservice。请帮我,我想逐步完整的细节。谢谢提前
答案 0 :(得分:0)
你可以这样做:
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
或者您可以将最后的“if”替换为:
Uri resourceAddress = new Uri("http://www.someurl.com/~?lalala");
StorageFile img = await ApplicationData.Current.LocalFolder.GetFileAsync("ImageName.jpg");
Stream inputStream = await img.OpenStreamForReadAsync();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, resourceAddress);
HttpMultipartContent cont = new HttpMultipartContent();
cont.Add(new HttpStreamContent(inputStream.AsInputStream()));
cont.Headers.ContentType = new HttpMediaTypeHeaderValue("image/jpeg");
request.Content = cont;
request.Headers.Connection.Add(new HttpConnectionOptionHeaderValue("Keep-Alive"));
request.Content.Headers.ContentLength = (ulong)inputStream.Length;
HttpResponseMessage response = await httpClient.SendRequestAsync(request);
if (response.StatusCode == HttpStatusCode.Ok)
{
return true;
}
以下是github上官方样本的良好链接:HttpClient sample