パラメータfile1で画像をURIにアップロードする必要があるコードがあります。しかし、コードは機能しません。画像がアップロードされないのはなぜですか?
これが私のコードです:
public void Upload
{
string oauthUrl = "http://MY_Uri";
HttpClient theAuthClient = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, oauthUrl);
StorageFolder storageFolder = KnownFolders.PicturesLibrary;
StorageFile sf = await storageFolder.GetFileAsync("ss.png");
IBuffer buffer = await FileIO.ReadBufferAsync(sf);
byte[] fileData = buffer.ToArray();
Encoding encoding = Encoding.GetEncoding("Windows-1252");
string text = encoding.GetString(fileData, 0, fileData.Length);
string content = @"file1=" + text + "";
txt.Text = content;
StorageFolder storageFolder2 = KnownFolders.PicturesLibrary;
StorageFile sampleFile = await storageFolder2.CreateFileAsync("sample.txt");
await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "" + text + "");
request.Method = HttpMethod.Post;
request.Content = new StreamContent(new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(content)));
request.Content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
try
{
HttpResponseMessage response = await theAuthClient.SendAsync(request);
handleResponse(response);
}
catch (HttpRequestException hre)
{
}
}
public async void handleResponse(HttpResponseMessage response)
{
string content = await response.Content.ReadAsStringAsync();
Account account = JsonConvert.DeserializeObject<Account>(content);
if (content != null)
{
}
}