问题
I am trying to develop an application in C# which takes data from Service1(3rd party), processes it and then sends data to Service2(again 3rd party).
The data I am trying to receive, process and send is a pdf file
From Service1, I am receiving pdf file in a string variable.
e.g.
response.Content = "%PDF-1.4 \n1 0 obj\n<<\n/Pages 2 0 R\n/Type /Catalog\n>>\nendobj\n2 0 obj\n<<\n/Type /Pages\n/Kids [ 3 0 R 17 0 R ]\n/Count 2\n>>\nendobj\n3 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n/Resources <<\n/XObject << /Im0 8 0 R >>\n/ProcSet 6 0 R
>>\n/MediaBox [0 0 ..."
Now, Service2 requires PDF data to be in byte[] form
How do I convert response.Content i.e. string to byte[]?
FYI -
I have tried below method, but it didn't work. I am able to open file but it shows all junk values.
byte[] bitmapData = Encoding.UTF8.GetBytes(response.Content);
UPDATE : SOLVED
I just found that it was not Service1 which was sending data in string format, it's just I was using IRestResponse.Content
, a string variable from RestSharp instead of using IRestResponse.RawBytes
, a byte[] variable.
回答1:
I just found that it was not Service1 which was sending data in string format, it's just I was using IRestResponse.Content
, a string variable from RestSharp instead of using IRestResponse.RawBytes
, a byte[] variable.
来源:https://stackoverflow.com/questions/35242758/convert-pdf-file-received-in-string-variable-to-byte-array-in-c-sharp