public static String auth(String login, String password) throws IOException {
String data = String.format(
"username=%s&password=%s&locale=ru",
URLEncoder.encode(login, "UTF-8"),
URLEncoder.encode(password, "UTF-8")
);
Response resp = Request.builder().url("https://examlpe_some_site.com/bla/bla/bla/login")
.method("POST")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36")
.data(data.getBytes(StandardCharsets.UTF_8)).build().send();
return HttpCookie.parse(resp.getHeaders().get("Set-Cookie").get(0)).get(0).getValue();
}
можна просто повернути респонс : return resp
-
Good morning, I’m glad to help you, I already have experience in this field.
Andrei Wozniak
-
157 2 0 Hello to you,
The code is ready, I will send you as soon as you write.
I will be happy with personal messages.
-
423 15 0 If still relevant, ready to do right now through the library requests
-
23 Good morning, the code is ready.
Unfortunately, less than 500 UAH cannot be placed.
-
410 10 0 Good evening ! I am pleased to fulfill your task! I work 24/7
-
19 Here is the translation of this code from Java to Python:
Imported by urllib.parse
Import Requests
def auth (login and password)
URL = "https://example_some_site.com/Bla/Bla/Bla/Login"
data = {"Username": login, "Password": password, "Locale": "Ru"}
This is the beginning code, I already have a ready code for you.
…
This code does the same as the output code in Java. It accepts the login and password as arguments, forms the request using the requests library, sends it to the server and returns the cookie value. It is important to note that the urllib.parse module is used to code the URL and data forms.
-
7844 96 0 Hello, you are ready to do everything right now. Write it.
Unfortunately I can’t put less than 500 :(
-
543 19 2 Good night, ready to help you. I wait for answers.
Online 24/7
-
Alex Boird H@B
import urllib.parse import requests def auth(login, password): data = urllib.parse.urlencode({ "username": login, "password": password, "locale": "ru" }).encode('utf-8') headers = { "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" } response = requests.post("https://example/bla/bla/login", headers=headers, data=data) print(response.text) print(response.status_code) # set_cookie_header = response.headers.get("Set-Cookie") # cookie_value = Cookie().parse(set_cookie_header).get(0).value # return cookie_value auth(login,password)ось таке на пайтоні не працює = раптом хтось хотів так написати
а на джава те що дав в завданні - працює
-
Доброго дня, код готовий
Нажаль нижче 500 грн не можу поставити
Можу відправити вам результат у приватні повідомлення для перевірки -
Alex Boird H@B
задачу вирішено
data = urllib.parse.urlencode({ "username": login, "password": password, "locale": "ru" }).encode('utf-8')ось такий код, багато хто писав - він не правильний
бо не правильно з джава на пайтон то переаодили,
на джава чітко аписано що стрічку ми урл енкоде на джава робили, і не всього дікту, а логіну і пасворду тільки
і на пайтону урленкоде не дікта робити, а саме для стрічки !!!
-
Current freelance projects in the category Java
Development of an Android application player for the online TV service
609 USD
We need an Android developer to create a native Android application for an online TV service. Two versions are planned: for mobile devices: smartphones and tablets; for Android TV / Android STB: set-top boxes. Estimated timeline: up to 3 months. Estimated budget: 150,000… Java, App Development for Android ∙ 24 days 19 hours back ∙ 31 proposals |