Repository navigation
Closed
Labels
platform/wasm 🌐Categorizes an issue or PR as relevant to the WebAssembly platformquestionFurther information is requested
Description
this code works on uwp project but not work on web assembly project
Test example:
public static class SignalGoHelper
{
public static string HostUrl { get; set; } = "http://88.99.244.66:3817/";
private static HttpClient CreateHttp()
{
#if __WASM__
var handler = new Uno.UI.Wasm.WasmHttpHandler();
var httpClient = new HttpClient(handler);
#else
var httpClient = new HttpClient();
#endif
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/json"));
return httpClient;
}
public static async Task<T> PostDataAsync<T>(string url, params Tuple<string, object>[] parameters) where T : class, new()
{
var taskCompletionSource = new TaskCompletionSource<T>();
url = HostUrl + url;
MultipartFormDataContent form = new MultipartFormDataContent();
var request = CreateHttp();
foreach (var item in parameters)
{
Console.WriteLine(item.Item1 + " " + item.Item2);
var jsonPart = new StringContent(JsonConvert.SerializeObject(item.Item2), Encoding.UTF8, "application/json");
jsonPart.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
jsonPart.Headers.ContentDisposition.Name = item.Item1;
jsonPart.Headers.ContentType = new MediaTypeHeaderValue("application/json");
form.Add(jsonPart);
}
var response = await request.PostAsync(url, form);
var responsePayload = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(responsePayload);
}
} private async void btnLogin_Click(object sender, RoutedEventArgs e)
{
try
{
var result = await SignalGoHelper.PostDataAsync<MessageContract<UserInfo>>("Authentication/Login",
new Tuple<string, object>("userName", txtUsername.Text), new Tuple<string, object>("password", txtPassword.Text));
if (result.IsSuccess)
{
}
else
{
}
}
catch (Exception ex)
{
}
}Metadata
Metadata
Assignees
Labels
platform/wasm 🌐Categorizes an issue or PR as relevant to the WebAssembly platformquestionFurther information is requested
Activity
[-]Bug: MultipartFormDataContent not worl on web assembly[/-][+]Bug: MultipartFormDataContent not works on web assembly[/+]Ali-YousefiTelori commentedon Jun 24, 2018
I test again that works, no bug was there but my mistake
jeromelaban commentedon Jun 26, 2018
Thank you for the clarification, glad it's working for you.
Merge pull request unoplatform#62 from unoplatform/pj/ios-splashscree…
chore: MOAR LOGGING
chore: MOAR LOGGING