c# - how to upload a pdf file and other string parameter in rest wcf service -
i had created rest wcf service , want post pdf file , other string data correct way it
1) converting pdf base64 string , form xml , post rest web service decode in rest service.
2) directly uploading using below code
byte[] pdffile = file.readallbytes("pdf file path here");webrequest request = webrequest.create("https://test.site.fr/testfile"); request.method = "post"; request.contentlength = pdffile.length; request.contenttype = "application/pdf"; stream stream = request.getrequeststream(); stream.write(pdffile, 0, pdffile.length); stream.close(); httpwebresponse response = (httpwebresponse)request.getresponse(); streamreader reader = new streamreader(response.getresponsestream()); console.writeline(reader.readtoend()); reader.close();
which better respect large files , if other compression required
the best way use multipart/form-data. c# not have inbuilt multipart/form-data parser use parser written 1 of developers c# community.
Comments
Post a Comment