Okay, so let's do this. We've taken a look
at our HTTP traffic from our client application. Let's go
back to the browser and see what it's doing differently.
We going to go look at the network request again and
if I scroll up, there's a cookie here, there's
some session data that is being maintained by the browser
and passed along. That's potentially at least part of the
problem, so. What we can do then is actually maintain
session state in our code. So what I've done
here is modified what we looked at before. And in
this case, we're going to use a session object
instead of just a request object to do both our
get and our post. We'll be using the same
session object, so any session information that we get back
from this first request, will be maintained and passed
along when we make this request. Alright, let's run this.
Let me go back to the browser and see if we've
got a correct response or a response that gives us back
the data we're hoping to get. And now we could see
that the data we get, is actually what we were expecting. So,
note that this is actually a local file and is in
fact the local file that we were writing out here. And
we've got the right settings here, what we would have expected
had we actually submitted this through the browser. And, we're pulling back
the data that we hoped to get. Still missing the CSS files, but we don't
care all we care about is this data right here. Whoo hoo! We did it!
حسنًا، فلنقم بذلك. لقد ألقينا نظرة
على حركة مرور HTTP من تطبيق العميل لدينا. فلنرجع
.إلى المتصفح ونرَ ما الذي يفعله على نحوٍ مختلف
سنلقي نظرة على طلب الشبكة مرة أخرى
وإذا قمت بالتمرير لأعلى، فسأجد ملف تعريف ارتباط هنا كما توجد
بعض بيانات جلسة يحتفظ المتصفح بها
ويمررها للأمام. من المحتمل أن يكون ذلك على الأقل جزءًا من
المشكلة. ما يمكننا القيام به عندئذٍ هو المحافظة بالفعل
على حالة الجلسة في تعليماتنا البرمجية. لذلك ما قمت به
هنا هو تعديل ما ألقينا نظرة عليه من قبل. وفي
هذه الحالة، سنستخدم كائن جلسة
بدلاً من مجرد كائن طلب للقيام بطلب
get وpost معًا. سنستخدم
كائن الجلسة نفسه، ومن ثم فأي معلومات جلسة نحصل عليها
من هذا الطلب الأول سيتم الاحتفاظ بها وتمريرها
.للأمام عند إجراء هذا الطلب. حسنًا، فلنشغل هذا
اسمح لي بالعودة إلى المتصفح وأرى ما إذا حصلنا على
الرد الصحيح أو رد يُرجع إلينا
البيانات التي كنا نأمل الحصول عليها. والآن نرى
،أن البيانات التي حصلنا عليها هي ما كنا نتوقعه بالفعل. إذًا
لاحظ أن هذا هو ملف محلي وفي
الحقيقة هو الملف المحلي الذي كنا نكتبه هنا. ولقد
حصلنا على الإعدادات المناسبة هنا، ما كنا نتوقعه
حال قيامنا بإرسال ذلك عبر المتصفح بالفعل. وكنا نقوم باسترداد
البيانات التي كنا نأمل في الحصول عليها. لا زلنا نفتقد ملفات CSS، لكننا لا نكترث
!لذلك وكل ما يهمنا هو هذه البيانات الموجودة هنا. رائع! لقد فعلناها
Vamos executar isso. Analisamos
o tráfego HTTP do nosso aplicativo cliente. Vamos
voltar ao navegador e ver o que ele está fazendo de diferente.
Vamos analisar a solicitação de rede de novo e
se eu rolar para cima, há um cookie aqui, há
alguns dados da sessão que estão sendo mantidos pelo navegador
e repassados. Aqui está pelo menos parte do
problema. O que podemos fazer é realmente manter
o estado da sessão em nosso código. O que fiz aqui
foi modificar o que analisamos antes. E neste
caso, vamos usar um objeto da sessão,
em vez de apenas um objeto da solicitação para
get e post. Vamos usar o mesmo
objeto da sessão, dessa forma, quaisquer informações sobre a sessão que obtivermos
desta primeira solicitação serão mantidas e transmitidas
quando fizermos a solicitação. Vamos fazer isso.
Vou voltar ao navegador e ver se
obtivemos uma resposta correta ou uma resposta que nos forneça
os dados que esperamos. Agora podemos ver
que os dados obtidos são realmente os esperados.
Observe que este é realmente um arquivo local, na
verdade, o arquivo local que estamos escrevendo aqui. E
obtivemos as configurações corretas aqui, o que esperávamos
foi realmente submetido através do navegador. E estamos extraindo
os dados que queríamos obter. Ainda faltam os arquivos CSS, mas
não importa, tudo de que precisamos está bem aqui. É isso aí! Conseguimos!
好 我们开始吧 我们已经研究了
通过客户端应用访问 HTTP 的流量
我们再回到浏览器 看看它的做法有何不同
我们要再研究下网络请求
如果我向上滚动 会看到这儿有个 cookie
有一些浏览器保留并传递的会话数据
这些可能至少是问题的一部分
因此 现在我们可以做的就是实际保留
我们代码中的会话状态 我在这里做的是
修改了我们之前所研究的内容
在该情况下 我们将使用会话对象
而不仅仅是一个请求对象
来进行获取和发帖行为 我们将使用相同的会话对象
我们从第一次请求中取回的任何会话信息
将被保留并在我们发出请求时传递出去
好 我们来运行吧
我们回到浏览器 看看
是否得到正确的响应 或者得到的响应
能返回我们希望得到的数据 现在我们可以看到
我们得到的数据实际就是我们所期望的
要注意 这实际是一个本地文件
实际是我们在这里写出的本地文件
这里的设置是正确的 正是我们所期望的情况
如果我们真的通过浏览器提交了
我们要提取我们希望得到的数据 现在还缺少 CSS 文件 不过我们不关心这个
我们只关心这里的数据 哇呼!我们成功了