Как отправить POST-запрос в C # на https://roblox.com/build/upload - PullRequest
0 голосов
/ 15 ноября 2018

Я пытался отправить запрос на сообщение https://roblox.com/build/upload. Я выяснил, какие данные необходимы для связи с Fiddler, а затем создал код для этого. Я заставил мою программу отправить запрос на эту ссылку, но она все равно продолжает выдавать ошибку 500. Кто-нибудь может сказать мне, как я могу это исправить? Что может быть причиной проблемы?

// Set boundary for web request
String boundary = "----WebKitFormBoundary8qNCfnj9Y5XkJz09";
byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");

// Create web request
HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create("https://www.roblox.com/build/upload");
wRequest.ContentType = "multipart/form-data; boundary=" + boundary;
wRequest.ServicePoint.Expect100Continue = false;
wRequest.Host = "www.roblox.com";
wRequest.Referer = "https://www.roblox.com/build/upload";
wRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36";
wRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
wRequest.Method = "POST";
wRequest.KeepAlive = true;
wRequest.CookieContainer = loginCookies;

Stream wRequestStream = wRequest.GetRequestStream();

// Prepare Content-Disposition strings
string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n";

string rvtData = string.Format(formdataTemplate, "__RequestVerificationToken", rvt);
string assetTypeIdData = string.Format(formdataTemplate, "assetTypeId", "2");//g_iAssetType.ToString());
string isOggUploadEnabledData = string.Format(formdataTemplate, "isOggUploadEnabled", "True");
string isTgaUploadEnabledData = string.Format(formdataTemplate, "isTgaUploadEnabled", "True");
string groupIdData = string.Format(formdataTemplate, "groupId", g_MainConfig[i].ToString());
string onVerificationPageData = string.Format(formdataTemplate, "onVerificationPage", "False");
string captchaEnabledData = string.Format(formdataTemplate, "captchaEnabled", "False");
string nameData = string.Format(formdataTemplate, "name", name);
string fileData = string.Format(headerTemplate, "file", file.ToString(), "image/png");

Byte[] rvtByte = Encoding.ASCII.GetBytes(rvtData);
Byte[] assetTypeIdByte = Encoding.ASCII.GetBytes(assetTypeIdData);
Byte[] isOggUploadEnabledByte = Encoding.ASCII.GetBytes(isOggUploadEnabledData);
Byte[] isTgaUploadEnabledByte = Encoding.ASCII.GetBytes(isTgaUploadEnabledData);
Byte[] groupIdByte = Encoding.ASCII.GetBytes(groupIdData);
Byte[] onVerificationPageByte = Encoding.ASCII.GetBytes(onVerificationPageData);
Byte[] captchaEnabledByte = Encoding.ASCII.GetBytes(captchaEnabledData);
Byte[] nameByte = Encoding.ASCII.GetBytes(nameData);
Byte[] fileByte = Encoding.ASCII.GetBytes(fileData);
Byte[] realFileByte = File.ReadAllBytes(Environment.CurrentDirectory + "\\Files\\" + g_sAssetType + "\\" + file);

wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(rvtByte, 0, rvtByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(assetTypeIdByte, 0, assetTypeIdByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(isOggUploadEnabledByte, 0, isOggUploadEnabledByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(isTgaUploadEnabledByte, 0, isTgaUploadEnabledByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(groupIdByte, 0, groupIdByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(onVerificationPageByte, 0, onVerificationPageByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(captchaEnabledByte, 0, captchaEnabledByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(fileByte, 0, fileByte.Length);
wRequestStream.Write(realFileByte, 0, realFileByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES
wRequestStream.Write(nameByte, 0, nameByte.Length);
wRequestStream.Write(boundaryBytes, 0, boundaryBytes.Length); // BOUNDARY BYTES

wRequestStream.Close();
var wresp = wRequest.GetResponse();
Stream stream2 = wresp.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
string responseData = reader2.ReadToEnd();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...