SHADY84PL utworzono 29 listopada 2014 utworzono 29 listopada 2014 (edytowane) Witam jestem początkującym Programistą i mam problem z Fotka Api ale może po kolei potrafię się zalogować ,i formularz mi zwraca następujące dane http://www.fotka.pl/api/user/login, tylko teraz nie wiem jak się odwołać np do login ,user_id ,np: chcę aby do text boxu pobrać sessionId lub login i go wyświetlić jest to aplikacja Winform korzystam z cookie Containera ale niewiem jak wyciągnąć dane proszę o zrozumienie mojego problemu ,i liczę na jakąś linijkę kodu która mogłaby mi pomóc dodam że program piszę w języku C# using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net; using System.IO; namespace Fotka_Manager { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string url = "http://api.fotka.pl/v2/user/login?"; CookieContainer cookies = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "GET"; request.CookieContainer = cookies; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Close(); /////////////////////////////////////////////////////////////////////////////////// request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; request.CookieContainer = cookies; string login = ""; string haslo = ""; login = textBox1.Text; haslo = textBox2.Text; String userData = "login=" + login + "&password=" + haslo; request.ContentType="application/x-www-form-urlencoded"; byte[] userDataBytes = Encoding.ASCII.GetBytes(userData); Stream postData = request.GetRequestStream(); postData.Write(userDataBytes,0,userDataBytes.Length); postData.Close(); response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); richTextBox1.Text= (new StreamReader(stream,Encoding.GetEncoding("UTF-8"))).ReadToEnd(); response.Close(); stream.Close(); } } }
rafalluz komentarz 29 listopada 2014 komentarz 29 listopada 2014 http://www.fotka.pl/api/user/about Piszą, że potrzebny jest user_id lub login. Skoro możesz się zalogować, login masz, więc query powinno zwrócić rezultat. Przedebugguj kod i obejrzyj, co znajduje się w odpowiedzi oraz w cookiesach.
SHADY84PL komentarz 29 listopada 2014 Autor komentarz 29 listopada 2014 (edytowane) przydałby się kod na wydobycie informacji z session id :)
Wciąż szukasz rozwiązania problemu? Napisz teraz na forum!
Możesz zadać pytanie bez konieczności rejestracji - wystarczy, że wypełnisz formularz.