JavaRush /Java Blog /Random-IT /JSOUP + risposta multiparte/dati del modulo
wildsinner
Livello 41
Самара

JSOUP + risposta multiparte/dati del modulo

Pubblicato nel gruppo Random-IT
Buon pomeriggio. In generale, è necessario inviare i dati al sito sotto forma di risposta nel modulo multipart/form-data. Non è difficile intercettare una richiesta generata da un browser, ma eseguire la stessa tramite JSOUP è difficile. Ad esempio, puoi prendere il modulo più semplice che genererà la richiesta desiderata.
Intestazioni delle richieste Vengono visualizzate le intestazioni provvisorie Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Content-Type:multipart/form-data; border=----WebKitFormBoundaryjtkXVNw9YVG1H2P9 Origine:null Richieste di aggiornamento non sicure:1 Agente utente:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, come Gecko) Chrome/47.0.2526.106 Safari/537.36 X - DevTools-Emulate-Network-Conditions-Client-Id:8DCCE949-56FA-4AB0-81B7-DA2BC7960E5C ->Richiedi payload ------WebKitFormBoundaryjtkXVNw9YVG1H2P9 Content-Disposition: form-data; nome="testo" testo predefinito ------WebKitFormBoundaryjtkXVNw9YVG1H2P9 Disposizione contenuto: form-data; nome="file1"; nomefile="" Tipo di contenuto: application/octet-stream ------WebKitFormBoundaryjtkXVNw9YVG1H2P9 Disposizione del contenuto: form-data; nome="file2"; filename="" Content-Type: application/octet-stream ------WebKitFormBoundaryjtkXVNw9YVG1H2P9-- Ho provato in vari modi a generare una richiesta simile con diverse opzioni, e ho optato per questa, ma finora "balla con i tamburelli" non produce risultati. Forse qualcuno ha esperienza in questa materia. Se non ti dispiace, per favore indirizzami sulla strada giusta. È anche possibile che esista un modo per intercettare una richiesta generata da JSOUP, che in linea di principio ci consentirebbe anche di andare avanti. Grazie Map responseMap= new HashMap (); String key1 = "------WebKitFormBoundary9A3GpeDAwfa0TBDK\r\n" + "Content-Disposition: form-data; name=\"text\"\r\n\r\n"; String value1 = "text default"; headersMap.put(key1, value1); String key2 = "\r\n------WebKitFormBoundary9A3GpeDAwfa0TBDK\r\n" + "Content-Disposition: form-data; name=\"doc_sma_ref_file\"; filename=\"\"" + "\r\nContent-Type: application/octet-stream\r\n\r\n"; String value2 = ""; headersMap.put(key2, value2); String key3 = "\r\n------WebKitFormBoundary9A3GpeDAwfa0TBDK\r\n" + "Content-Disposition: form-data; name=\"doc_val_ref_file\"; filename=\"\"" + "\r\nContent-Type: application/octet-stream\r\n\r\n"; String value3 = ""; headersMap.put(key3, value3); String key4 = "\r\n------WebKitFormBoundary9A3GpeDAwfa0TBDK--"; String value4 = ""; headersMap.put(key4, value4); Connection.Response resBGT = Jsoup.connect(URL) .header("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundary9A3GpeDAwfa0TBDK") .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36") .followRedirects(true) .data(responseMap) .cookies(cookies) .ignoreHttpErrors(true) .timeout(15000) .method(Connection.Method.POST) .execute();
Commenti
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION