c# - Https upload MultipartForm returns 401 unauthorized -


i’m trying upload coverity scan result coverity.

this code:

public static void main( string[] args ) {     var client = new httpclient     {         timeout = timespan.fromminutes( 20 )     };     var form = new multipartformdatacontent     {         { new stringcontent( "my tooken" ), "token" },         { new stringcontent( "my email" ), "email" },         { new stringcontent( "1.1.1.1" ), "version" },         { new stringcontent( "test..." ), "description" }     };      var fs = new filestream( @"cov-int.zip", filemode.open, fileaccess.read );     form.add(new streamcontent(fs), "file", "cov-int.zip");      var task = client.postasync("https://scan.coverity.com/builds?project=name/porject", form);     try     {         task.wait();     }     catch ( aggregateexception ex )     {         throw ex.innerexception;     }     var result = task.result;     fs.close(); } 

the post end failed status (401 unauthorized):

{statuscode: 401, reasonphrase: 'unauthorized', version: 1.1, content: system.net.http.streamcontent, headers: {   x-xss-protection: 1; mode=block   x-request-id: 70dfc119-7d78-47fe-86a7-8505d73225e4   x-runtime: 1.675468   x-frame-options: sameorigin   x-content-type-options: nosniff   connection: close   status: 401 unauthorized   transfer-encoding: chunked   cache-control: no-cache   date: fri, 29 may 2015 13:01:06 gmt   server: apache   x-powered-by: phusion passenger 5.0.8   content-type: text/html; charset=utf-8 }} 

i’ve tried upload same data, same machine same server using curl:

curl --form token="token" --form email="email" --form file="cov-int.zip" --form version="1.1.1.1" --form description="a message" --insecure https://scan.coverity.com/builds?project=name/project 

uploading data curl works.

what doing wrong in c# code?

something possibly changed on coverity's end, since working 2 weeks ago. based on other question here how upload files asp.net mvc 4.0 action running in iis express httpclient class included in .net 4.0 i've found think solution.

you need add quotes form-data names.

var form = new multipartformdatacontent {     { new stringcontent( "my tooken" ), "\"token\"" },     { new stringcontent( "my email" ), "\"email\"" },     { new stringcontent( "1.1.1.1" ), "\"version\"" },     { new stringcontent( "test..." ), "\"description\"" } };  form.add(new streamcontent(fs), "\"file\"", "cov-int.zip"); 

can't 100% sure works since used attempts today , have wait until tomorrow see success response. getting "the build submission quota project has been reached." message , not access denied message now.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -