Home > Net >  POST interface to upload the file 1 m sure more than 1 m tips below 500 error
POST interface to upload the file 1 m sure more than 1 m tips below 500 error

Time:10-18

POST interface to upload the file 1 m sure more than 1 m tips below 500 error

Public static string webPost (string apiurl, string fpath, string type, string access_token, AttachmentInfo atts)
{
String a boundary="-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" + DateTime. Now. Ticks. ToString (" x ");
Byte [] boundarybytes=Encoding. The ASCII. GetBytes (" \ r \ n - "+ boundary +" \ r \ n ");
Byte [] endbytes=Encoding. The ASCII. GetBytes (" \ r \ n - "+ boundary +" -- \ r \ n ");
ServicePointManager. CheckCertificateRevocationList=true;
ServicePointManager. DefaultConnectionLimit=512;
ServicePointManager. Expect100Continue=true;
ServicePointManager. ServerCertificateValidationCallback delegate of={return true; };
//1. HttpWebRequest
System. The GC. Collect ();
HttpWebRequest request=(HttpWebRequest) WebRequest. Create (apiurl);
Request. The ContentType="multipart/form - data; A boundary="+ boundary;
Request. The Method=type;
Request. The KeepAlive=false;
//request. Credentials=CredentialCache. DefaultCredentials;
The string head="Bearer" + access_token;
Request. Headers. The Add (" Authorization ", the head);
Request. Timeout=1000 * 3600;
Request. ReadWriteTimeout=1000 * 3600;

Using (Stream Stream=request. GetRequestStream ())
{
String headerTemplate="Content - Disposition: the form - data; Name=\ "{0} "; Filename=\ "{1} \ \ r \ nContent" -type: application/octet - stream \ r \ n \ r \ n ";
Byte [] buffer=new byte [4096].
Int bytesRead=0;
The string header=the string. Format (headerTemplate, "file", atts Name);
Byte [] headerbytes=Encoding. GetEncoding (" utf-8 "). GetBytes (header);


//1.2 file
Stream. Write (boundarybytes, 0, boundarybytes. Length);
Stream. Write (headerbytes, 0, headerbytes. Length);
Using (FileStream fileStreamss=new FileStream (fpath, FileMode. Open, FileAccess. Read))
{
While ((bytesRead=fileStreamss. Read (buffer, 0, buffer Length))!=0)
{
Stream. Write (buffer, 0, bytesRead);
}
}

//1.3 form the end
Stream. Write (endbytes, 0, endbytes. Length);
}
//2. WebResponse
The string result;
Try
{
Request. The ProtocolVersion=HttpVersion. Version10;

HttpWebResponse response=(HttpWebResponse) request. The method GetResponse ();
StreamReader StreamReader=new StreamReader (response. GetResponseStream (), Encoding, UTF8);
A string of text=streamReader. ReadToEnd ();
Result=text;
The response. The Close ();
}
The catch (Exception ex)
{
Result=ex. The Message;
}
The finally
{
Request. The Abort ();
System. The GC. Collect ();
}
return result;

}

CodePudding user response:

Various configurations are tried is still the same error, such as

Opposite party b your side try upload is no problem

CodePudding user response:

Two problems, the recipient's biggest receive files, as well as local upload the configuration file size,
Limit problem,

CodePudding user response:

Caught look, isn't it server has limit, return error messages
  • Related