Jump to content

Recommended Posts

1 hour ago, Cường Seven said:

Lỗi không login được ạ! Kết quả trả về vẫn như vậy: {"Data":null,"Status":false,"Message":"Thực hiện xác nhận người máy không thành công.","ErrorCode":null,"Code":null}

Cái này chắc phải làm thêm gì ấy ạ! Vì mình có dùng HTTP Header LIVE để POST lại đoạn login vẫn báo như trên ạ!

code bạn bình thường , chỉ sai cái content-type thôi , thay  :

Trích dẫn

application/x-www-form-urlencoded; charset=UTF-8

thành :

Trích dẫn

application/json; charset=utf-8

là được. như này nè 

html = http.Post("https://id.muaban.net/home/AjaxLogin", datalogin, "application/json; charset=utf-8").ToString();

 

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
13 phút trước, Thiên Chi Kiều Nữ said:

code bạn bình thường , chỉ sai cái content-type thôi , thay  :

thành :

là được. như này nè 


html = http.Post("https://id.muaban.net/home/AjaxLogin", datalogin, "application/json; charset=utf-8").ToString();

 

Wow đã được rồi ạ! Em cảm ơn c nhiều nhé <3

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
4 giờ trước, Khirk said:

Cho mình hỏi , mình có api up file lên qua xnet mà báo lỗi 400, mong bạn giúp

spacer.pngspacer.png

bạn vui lòng copy code lên cho mỵ sửa nhé =.='' gõ lại mỏi tay quớ... với lại mỵ cũng không thấy lỗi báo thế nào cả thì sao mà sửa cho bạn =.=''

Hoặc thông tin ở trang nào nữa mỵ mới giúp được..thế kia thì mỵ chịu nha.

Edit : Lỗi status code 400 là sai data body .. bạn có thể google lỗi status code là ra :">

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
Trích dẫn

  			HttpRequest _httprequest_UP = new HttpRequest();
            string path = @"D:\downlaod\260a2b4d1855d00b8944.jpg";
            MultipartContent data = new MultipartContent() {
                { new FileContent(path), "file	", "blod"},
                { new StringContent("description"), "ic_upload_file"},
                { new StringContent("title	"), "upload_file"}
            };

            _httprequest_UP.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.40";
            _httprequest_UP.AddHeader("Token-id", "d00d8c4a-e108-46b1-e053-63199f0a7fe3");
            _httprequest_UP.AddHeader("Token-key", "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJbtOriG8bPoOS11HWANn+yz3wu+KpBHIrpcOgPQcNzQ2jIYkERb8iAHAn5ZyvlPklzogbeOPmNHPkSWVk7wxzkCAwEAAQ==");

            _httprequest_UP.AddHeader("Authorization", "bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1YWYwNzhjNy0zZTRmLTExZWMtODZiNy05MTc2MDJlNjY4NmQiLCJhdWQiOlsicmVzdHNlcnZpY2UiXSwidXNlcl9uYW1lIjoicHR0aGFuMmtAZ21haWwuY29tIiwic2NvcGUiOlsicmVhZCJdLCJpc3MiOiJodHRwczovL2xvY2FsaG9zdCIsIm5hbWUiOiJwdHRoYW4ya0BnbWFpbC5jb20iLCJ1dWlkX2FjY291bnQiOiI1YWYwNzhjNy0zZTRmLTExZWMtODZiNy05MTc2MDJlNjY4NmQiLCJhdXRob3JpdGllcyI6WyJVU0VSIl0sImp0aSI6ImE5MmQ1NjcwLTk3YTEtNGY3ZS05YjQ1LWU2YTg5ZTY5OGMxNCIsImNsaWVudF9pZCI6ImFkbWluYXBwIn0.OdgRS64maexJ41blqFVGfNiC3AsyXeFa-O1ZSXjQi1wSpOMFM8slGWgCek_sWLaWZ6ILnAajdg_8GQHiy6lkHElsR_BwGcUG1OoN5JHOLBkGfxA6brJMnO3TPtQ3U6tjDTW0lGUA8Y060ZGMnulvhVxyTt6ncS_ssYbi0C03gTqZMCk1zDIj-FJJXziYckEi4-YPl9IDwH3zjWhMKtiaB3UthX-3rVSyYgPik2HimV6J6tzZr9Gav50vb3N6iooVyGPIhFoUqEdMG27tbXF1IYUKfU-pAOtgyktfcoLCcC7O5FhfcTVrCdgtxZACU5cM0XgOZuHUnLtLKXN_VQFMeA");

            //string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
            string UPCMTTRUOC = _httprequest_UP.Post(new Uri("https://api.idg.vnpt.vn/file-service/v1/addFile"), data).ToString();
            MessageBox.Show(UPCMTTRUOC);

 

Đoạn code đây ạ
E viết theo api của VNPT eKYC ạ 
mong C giúp
em xin cảm ơn

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
1 giờ trước, Khirk said:

Đoạn code đây ạ
E viết theo api của VNPT eKYC ạ 
mong C giúp
em xin cảm ơn

bạn sai đoạn data thôi , đảo ngược lại key với value là được nhé.

MultipartContent data = new MultipartContent()
{
       { new FileContent(path), "file", "blod"},
       { new StringContent("ic_upload_file"), "description"},
       { new StringContent("upload_file"),"title"}
};

2kf0rBL.png

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites

À kết quả trả về như trên mà e muốn JsonConvert.DeserializeObject
mà cái class object nó lại k tạo được tên trùng chữ object thì phải làm sao ạ

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
5 giờ trước, Khirk said:

À kết quả trả về như trên mà e muốn JsonConvert.DeserializeObject
mà cái class object nó lại k tạo được tên trùng chữ object thì phải làm sao ạ

bạn dùng dùng hàm jsonobject parse ra rồi sử dụng thử

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites

E là newbie C# nên mọi người giúp e case này với. E sử dụng HttpRequest bên Autoit thì up file lên OK nhưng qua Xnet thì ko Up file lên đc, không biết lỗi ở đâu mong mọi người giải đáp giúp em ạ!

------------------------------------------------  XNET ----------------------------------------------------------------------------------------------

            string cookie_login = http.Response.Cookies.ToString();
            string rToken = GetData(http,"https://172.16.20.150/ccmadmin/bulkfileuploadEdit.do");
            string token = getTokenUpload(rToken);
            string path = @"C:\Users\longqh\source\repos\Cisco Universe\bin\Debug\TUBQ_UPDATE.csv";
            MultipartContent data = new MultipartContent()
            {
                {new StringContent("struts.token.name"),"token"},
                {new StringContent("token"),token},
                {new StringContent("pkid")," "},
                {new StringContent("filename"),path},
                {new StringContent("idval"),"0"},
                {new StringContent("searchString"),"0"},
                {new StringContent("activebps")," "},
                {new StringContent("file"),path},
                {new StringContent("selecttheentity"),"2"},
                {new StringContent("selecttransactiontype"),"33"},
                {new StringContent("overwriteExistingFile"),"true"},
                {new StringContent("__checkbox_overwriteExistingFile"),"true"}
            };
            var html = UploadData(http, "https://172.16.20.150/ccmadmin/bulkfileuploadSave.do", data, "multipart/form-data",cookie: cookie_login);

------------------------------------- AUTOIT httprequest --------------------------------------------------------------------------

Func upCSV_UpdateUser()
    $filePath = @ScriptDir&'\'&$ldap_id&'_UPDATE.csv'
    $r_token = _HttpRequest(2,'https://172.16.20.150/ccmadmin/bulkfileuploadEdit.do',$cookie_login)
    $token_upload = StringRegExp($r_token,'value="(.*?)" \/>',3)[1]
    Local $aForm = [['struts.token.name', 'token'], ['token', $token_upload], ['pkid', ''], ['filename', $filePath], ['idval','0'],['searchString','0'],['activebps',''],['$file', $filePath],['selecttheentity','2'],
                                  ['selecttransactiontype','33'],['overwriteExistingFile','true']]
    $dataPos=_HttpRequest_DataFormCreate($aForm)
    $upload_file = _HttpRequest(2, 'https://172.16.20.150/ccmadmin/bulkfileuploadSave.do', $dataPos)
EndFunc

 

------------------------------- firefox -----------------------------------

spacer.png

 

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
3 giờ trước, mrq1991 said:

E là newbie C# nên mọi người giúp e case này với. E sử dụng HttpRequest bên Autoit thì up file lên OK nhưng qua Xnet thì ko Up file lên đc, không biết lỗi ở đâu mong mọi người giải đáp giúp em ạ!

------------------------------------------------  XNET ----------------------------------------------------------------------------------------------

            string cookie_login = http.Response.Cookies.ToString();
            string rToken = GetData(http,"https://172.16.20.150/ccmadmin/bulkfileuploadEdit.do");
            string token = getTokenUpload(rToken);
            string path = @"C:\Users\longqh\source\repos\Cisco Universe\bin\Debug\TUBQ_UPDATE.csv";
            MultipartContent data = new MultipartContent()
            {
                {new StringContent("struts.token.name"),"token"},
                {new StringContent("token"),token},
                {new StringContent("pkid")," "},
                {new StringContent("filename"),path},
                {new StringContent("idval"),"0"},
                {new StringContent("searchString"),"0"},
                {new StringContent("activebps")," "},
                {new StringContent("file"),path},
                {new StringContent("selecttheentity"),"2"},
                {new StringContent("selecttransactiontype"),"33"},
                {new StringContent("overwriteExistingFile"),"true"},
                {new StringContent("__checkbox_overwriteExistingFile"),"true"}
            };
            var html = UploadData(http, "https://172.16.20.150/ccmadmin/bulkfileuploadSave.do", data, "multipart/form-data",cookie: cookie_login);

------------------------------------- AUTOIT httprequest --------------------------------------------------------------------------

Func upCSV_UpdateUser()
    $filePath = @ScriptDir&'\'&$ldap_id&'_UPDATE.csv'
    $r_token = _HttpRequest(2,'https://172.16.20.150/ccmadmin/bulkfileuploadEdit.do',$cookie_login)
    $token_upload = StringRegExp($r_token,'value="(.*?)" \/>',3)[1]
    Local $aForm = [['struts.token.name', 'token'], ['token', $token_upload], ['pkid', ''], ['filename', $filePath], ['idval','0'],['searchString','0'],['activebps',''],['$file', $filePath],['selecttheentity','2'],
                                  ['selecttransactiontype','33'],['overwriteExistingFile','true']]
    $dataPos=_HttpRequest_DataFormCreate($aForm)
    $upload_file = _HttpRequest(2, 'https://172.16.20.150/ccmadmin/bulkfileuploadSave.do', $dataPos)
EndFunc

 

------------------------------- firefox -----------------------------------

spacer.png

 

web nội bộ, mỵ không biết đc bạn đúng hay sai ntn, code bạn up lên cũng không đầy đủ .

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
1 hour ago, Thiên Chi Kiều Nữ said:

web nội bộ, mỵ không biết đc bạn đúng hay sai ntn, code bạn up lên cũng không đầy đủ .

Web nội bộ này đơn giản lắm ạ. Cứ lấy token xong Post là được ạ. Trước em dùng cái HttpRequest của bác Huân Hoàng thì nó ra được dạng giống FireFox gửi đi. Còn C# thì em đang ko biết view data dạng MultipartContent này ntn nên không biết data gửi đi như thế nào. E mới học C# nên c Mỵ đừng cười e ạ :)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using xNet;

namespace test_Request
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        void AddCookie(HttpRequest http, string cookie)
        {
            var temp = cookie.Split(';');
            foreach (var item in temp)
            {
                var temp2 = item.Split('=');
                if (temp2.Count() > 1)
                {
                    http.Cookies.Add(temp2[0], temp2[1]);
                }
            }
        }

        string GetData(HttpRequest http, string url, string cookie = null)
        {
            string html = http.Get(url) + "";
            http.Cookies = new CookieDictionary();
            if (!string.IsNullOrEmpty(cookie))
            {
                AddCookie(http, cookie);
            }
            if (http == null)
            {
                http = new HttpRequest();
                http.Cookies = new CookieDictionary();
            }
            return html;
        }

        string PostData(HttpRequest http, string url, string data = null, string contentType = null, string userArgent = "", string cookie = null)
        {
            if (http == null)
            {
                http = new HttpRequest();
                http.Cookies = new CookieDictionary();
            }
            if (!string.IsNullOrEmpty(cookie))
            {
                AddCookie(http, cookie);
            }
            if (!string.IsNullOrEmpty(userArgent))
            {
                http.UserAgent = userArgent;
            }

            string html = http.Post(url, data, contentType) + "";
            return html;
        }

        string UploadData(HttpRequest http, string url, MultipartContent data = null, string contentType = null, string userArgent = "", string cookie = null)
        {
            if (http == null)
            {
                http = new HttpRequest();
                http.Cookies = new CookieDictionary();
            }
            if (!string.IsNullOrEmpty(cookie))
            {
                AddCookie(http, cookie);
            }
            if (!string.IsNullOrEmpty(userArgent))
            {
                http.UserAgent = userArgent;
            }
            string html = http.Post(url, data) + "";
            return html;
        }
        string getTokenUpload(string data)
        {
            Regex reg = new Regex(@"""token"" value=""(.*?)"" \/>");
            Match result = reg.Match(data);
            string token = result.ToString().Remove(0, 15);
            token = token.Remove(token.Length - 4);
            return token;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HttpRequest http = new HttpRequest();
            string un = "";
            string pw = "";
            GetData(http, "https://172.16.20.150/ccmadmin/showHome.do");
            string DataPost = "appNav=ccmadmin&j_username=" + WebUtility.UrlEncode(un) + "&j_password=" + WebUtility.UrlEncode(pw);
            string Content_Type = "application/x-www-form-urlencoded";
            string urlPost = "https://172.16.20.150/ccmadmin/j_security_check";
            string response = PostData(http, urlPost, DataPost, Content_Type).ToString();
            string cookie_login = http.Response.Cookies.ToString();
            string rToken = GetData(http,"https://172.16.20.150/ccmadmin/bulkfileuploadEdit.do");
            string token = getTokenUpload(rToken);
            string path = @"C:\Users\longqh\source\repos\Cisco Universe\bin\Debug\TUBQ_UPDATE.csv";
            MultipartContent data = new MultipartContent()
            {
                {new StringContent("struts.token.name"),"token"},
                {new StringContent("token"),token},
                {new StringContent("pkid")," "},
                {new FileContent(path),"filename"},
                {new StringContent("idval"),"0"},
                {new StringContent("searchString"),"0"},
                {new StringContent("activebps")," "},
                {new StringContent("file"),"TUBQ_UPDATE.csv"},
                {new StringContent("selecttheentity"),"2"},
                {new StringContent("selecttransactiontype"),"33"},
                {new StringContent("overwriteExistingFile"),"true"},
                {new StringContent("__checkbox_overwriteExistingFile"),"true"}
            };
            var html = UploadData(http, "https://172.16.20.150/ccmadmin/bulkfileuploadSave.do", data, "multipart/form-data",cookie: cookie_login);
        }
    }
}

 

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
6 giờ trước, mrq1991 said:

Web nội bộ này đơn giản lắm ạ. Cứ lấy token xong Post là được ạ. Trước em dùng cái HttpRequest của bác Huân Hoàng thì nó ra được dạng giống FireFox gửi đi. Còn C# thì em đang ko biết view data dạng MultipartContent này ntn nên không biết data gửi đi như thế nào. E mới học C# nên c Mỵ đừng cười e ạ :)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using xNet;

namespace test_Request
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        void AddCookie(HttpRequest http, string cookie)
        {
            var temp = cookie.Split(';');
            foreach (var item in temp)
            {
                var temp2 = item.Split('=');
                if (temp2.Count() > 1)
                {
                    http.Cookies.Add(temp2[0], temp2[1]);
                }
            }
        }

        string GetData(HttpRequest http, string url, string cookie = null)
        {
            string html = http.Get(url) + "";
            http.Cookies = new CookieDictionary();
            if (!string.IsNullOrEmpty(cookie))
            {
                AddCookie(http, cookie);
            }
            if (http == null)
            {
                http = new HttpRequest();
                http.Cookies = new CookieDictionary();
            }
            return html;
        }

        string PostData(HttpRequest http, string url, string data = null, string contentType = null, string userArgent = "", string cookie = null)
        {
            if (http == null)
            {
                http = new HttpRequest();
                http.Cookies = new CookieDictionary();
            }
            if (!string.IsNullOrEmpty(cookie))
            {
                AddCookie(http, cookie);
            }
            if (!string.IsNullOrEmpty(userArgent))
            {
                http.UserAgent = userArgent;
            }

            string html = http.Post(url, data, contentType) + "";
            return html;
        }

        string UploadData(HttpRequest http, string url, MultipartContent data = null, string contentType = null, string userArgent = "", string cookie = null)
        {
            if (http == null)
            {
                http = new HttpRequest();
                http.Cookies = new CookieDictionary();
            }
            if (!string.IsNullOrEmpty(cookie))
            {
                AddCookie(http, cookie);
            }
            if (!string.IsNullOrEmpty(userArgent))
            {
                http.UserAgent = userArgent;
            }
            string html = http.Post(url, data) + "";
            return html;
        }
        string getTokenUpload(string data)
        {
            Regex reg = new Regex(@"""token"" value=""(.*?)"" \/>");
            Match result = reg.Match(data);
            string token = result.ToString().Remove(0, 15);
            token = token.Remove(token.Length - 4);
            return token;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HttpRequest http = new HttpRequest();
            string un = "";
            string pw = "";
            GetData(http, "https://172.16.20.150/ccmadmin/showHome.do");
            string DataPost = "appNav=ccmadmin&j_username=" + WebUtility.UrlEncode(un) + "&j_password=" + WebUtility.UrlEncode(pw);
            string Content_Type = "application/x-www-form-urlencoded";
            string urlPost = "https://172.16.20.150/ccmadmin/j_security_check";
            string response = PostData(http, urlPost, DataPost, Content_Type).ToString();
            string cookie_login = http.Response.Cookies.ToString();
            string rToken = GetData(http,"https://172.16.20.150/ccmadmin/bulkfileuploadEdit.do");
            string token = getTokenUpload(rToken);
            string path = @"C:\Users\longqh\source\repos\Cisco Universe\bin\Debug\TUBQ_UPDATE.csv";
            MultipartContent data = new MultipartContent()
            {
                {new StringContent("struts.token.name"),"token"},
                {new StringContent("token"),token},
                {new StringContent("pkid")," "},
                {new FileContent(path),"filename"},
                {new StringContent("idval"),"0"},
                {new StringContent("searchString"),"0"},
                {new StringContent("activebps")," "},
                {new StringContent("file"),"TUBQ_UPDATE.csv"},
                {new StringContent("selecttheentity"),"2"},
                {new StringContent("selecttransactiontype"),"33"},
                {new StringContent("overwriteExistingFile"),"true"},
                {new StringContent("__checkbox_overwriteExistingFile"),"true"}
            };
            var html = UploadData(http, "https://172.16.20.150/ccmadmin/bulkfileuploadSave.do", data, "multipart/form-data",cookie: cookie_login);
        }
    }
}

 

bạn up cả lỗi lên mỵ mới biết lỗi gì chứ ...nhìn code không thì cũng chưa thấy gì lạ cả

với lại bạn nên viết thẳng trực tiếp ra khi chưa thạo, bạn viết thành hàm thế này làm rối hơn. Phần add cookie hình như lỗi ở đó bạn

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
On 9/9/2022 at 21:48, Thiên Chi Kiều Nữ said:

bạn up cả lỗi lên mỵ mới biết lỗi gì chứ ...nhìn code không thì cũng chưa thấy gì lạ cả

với lại bạn nên viết thẳng trực tiếp ra khi chưa thạo, bạn viết thành hàm thế này làm rối hơn. Phần add cookie hình như lỗi ở đó bạn

Mỵ cho mình hỏi:

- Mình thay giá trị chuỗi rỗng = Space có bị ảnh hưởng gì ko ạ tại xnet ko cho để giá trị là rỗng, và làm cách nào để xem đc nội dung cái data MutipartConent ạ

- Hình như xnet tự add cookie vào request khi login thành công đúng ko ạ.

spacer.png

spacer.png

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
19 phút trước, mrq1991 said:

Mỵ cho mình hỏi:

- Mình thay giá trị chuỗi rỗng = Space có bị ảnh hưởng gì ko ạ tại xnet ko cho để giá trị là rỗng, và làm cách nào để xem đc nội dung cái data MutipartConent ạ

- Hình như xnet tự add cookie vào request khi login thành công đúng ko ạ.

spacer.png

spacer.png

không phải space đâu, mỵ chưa thấy space bao giờ, bạn cứ để liền "" là được ...

Login thành công thì cookie nằm luôn trong request rồi bạn.

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Trả lời chủ đề này...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...