Response status code does not indicate success: 500 (Internal Server Error).
parent
b46e786ace
commit
57609e6ed3
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<project name="Hello World" default="build" basedir=".">
|
||||
<description>The Hello World of build files.</description>
|
||||
<property name="debug" value="true" overwrite="false" />
|
||||
<target name="clean" description="remove all generated files">
|
||||
<delete file="HelloWorld.exe" failonerror="false" />
|
||||
<delete file="HelloWorld.pdb" failonerror="false" />
|
||||
</target>
|
||||
<target name="build" description="compiles the source code">
|
||||
<solution configuration="release">
|
||||
<referenceprojects>
|
||||
<include name="test/isn.tests/isn.tests.csproj" />
|
||||
FreeSpeech FreeSpeech.Droid FreeSpeech.Gtk FreeSpeech.iOS FreeSpeech.UWP
|
||||
</referenceprojects>
|
||||
</solution>
|
||||
</target>
|
||||
</project>
|
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace isn
|
||||
{
|
||||
public static class UploadFilesToServerUsingHttpClient
|
||||
{
|
||||
public static PushReport UploadFilesToServer(Uri uri, FileInfo fi,
|
||||
string apikey)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("X-NuGet-Client-Version", Constants.ClientVersion);
|
||||
client.DefaultRequestHeaders.Add("X-NuGet-ApiKey", apikey);
|
||||
using (var multipartFormDataContent = new MultipartFormDataContent())
|
||||
{
|
||||
/* var values = new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("Id", Guid.NewGuid().ToString()),
|
||||
new KeyValuePair<string, string>("Key", "awesome"),
|
||||
new KeyValuePair<string, string>("From", "khalid@home.com")
|
||||
//other values
|
||||
};foreach (var keyValuePair in values)
|
||||
{
|
||||
multipartFormDataContent.Add(new StringContent(keyValuePair.Value),
|
||||
String.Format("\"{0}\"", keyValuePair.Key));
|
||||
} */
|
||||
multipartFormDataContent.Add(new ByteArrayContent(File.ReadAllBytes(fi.FullName)),
|
||||
'"' + "File" + '"',
|
||||
'"' + fi.Name + '"');
|
||||
|
||||
var result = client.PutAsync(uri, multipartFormDataContent).Result;
|
||||
result.EnsureSuccessStatusCode();
|
||||
if (result.IsSuccessStatusCode)
|
||||
{
|
||||
Task.Run(async ()=>
|
||||
{
|
||||
string report = await result.Content.ReadAsStringAsync();
|
||||
Console.WriteLine(report);
|
||||
}).Wait();
|
||||
|
||||
}
|
||||
return new PushReport();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue