繁体   English   中英

如何发送base64 image vie http Post请求?

[英]How to send base64 image vie http Post request?

我正在创建将图像发送到 web 服务器的应用程序,我的代码有一些问题:这是来自网站的示例:

    Get your API key from your account settings page. Each user is given a unique authentication token, we call it API key. It's a 32-characters string that looks like:2abc234de56fab7c89012d34e56f6789
This key will be used for all your requests to our server.
Submit a HTTP POST request to our API URL: http://azcaptcha.com/in.php with parameters corresponding to the type of your captcha.
Server will return captcha ID or an error code if something went wrong.
Make a timeout: 20 seconds for ReCaptcha, 5 seconds for other types of captchas.
Submit a HTTP GET request to our API URL: http://azcaptcha.com/res.php to get the result.
If captha is already solved server will return the answer in format corresponding to the type of your captcha.
By default answers are returned as plain text like: OK|Your answer. But answer can also be returned as JSON {"status":1,"request":"TEXT"} if json parameter is used.
If captcha is not solved yet server will return CAPCHA_NOT_READY result. Repeat your request in 5 seconds.
If something went wrong server will return an error code.
          

这是 Base64 样本表格

<form method="post" action="http://azcaptcha.com/in.php">
<input type="hidden" name="method" value="base64">
Your key:
<input type="text" name="key" value="YOUR_APIKEY">
The CAPTCHA file body in base64 format:
<textarea name="body">BASE64_FILE</textarea>
<input type="submit" value="Upload and get the ID">
</form> 

但是当我尝试发送它时,我从服务器收到错误消息,指出 base64 文件不可读,但是如果我通过 HTML 页面发送它并使用 base64 示例中的代码发送它,那么这是我的 C# 代码:

byte[] imageArray = System.IO.File.ReadAllBytes(@"C:\Users\Cvetan Tokov\Desktop\New folder\rep.png");
            string base64ImageRepresentation = Convert.ToBase64String(imageArray);
            richTextBox1.Text = base64ImageRepresentation;
           
             string key = "MY API KEY";
             ASCIIEncoding encoding = new ASCIIEncoding();
             string postData = richTextBox1.Text;

             byte[] data = encoding.GetBytes(postData);
             WebRequest request = WebRequest.Create("http://azcaptcha.com/in.php?key=MY API KEY&method=base64");
             request.Method = "post";
            
             request.ContentType = "text/html; charset=windows-1252";

            request.ContentLength = data.Length;

             using (Stream stream = request.GetRequestStream())
             {
                 stream.Write(data, 0, data.Length);
             }

此代码没有以正确的顺序发送 base64 字符串以从服务器读取,有人可以帮助我根据 C# 中的示例创建表单。

先感谢您

我建议你使用 web 嗅探器。 例如,HTTP 分析器。 打开它,通过浏览器和通过你的应用程序发送请求,然后比较有什么不同——主要看“Headers”和“Post data”选项卡。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM