doujiao1949 2014-11-20 22:02
浏览 69
已采纳

cURL - 提示脚本工作,而curl-php的相同请求不起作用(内部服务器错误500)

I'm trying to login in a website using my username and password.

I tried using cUrl from the prompt and i managed to do it in two steps: first of all I send a get request to a page to save the cookies, then i use those cookies to send a post request to another page that is the login page.

I'm doing it in this way because I'm trying to reproduce the requests logged in my browser's developer console.

These are the two commands that works

curl -c cookie.txt --location "ss16589.scuolanext.info" --cacert ca-bundle.crt



curl --location "https://www.portaleargo.it/argoweb/famiglia/common/j_security_check" --data "utente=xxxxxxx&j_password=xxxxxxx&j_username=xxxxxxx"%"23SS16589&submit=Entra" -b cookie.txt --cacert ca-bundle.crt

I need to develop a php page that can perform the same task.

This first page works. I get my cookie.txt full of delicious cookies.

<?php

$url = 'ss16589.scuolanext.info';

$cookie = __DIR__ . '/cookie.txt'; // file and folder must be writeable

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1000); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);

curl_setopt($ch, CURLOPT_CAINFO, getcwd().'\cacert.pem');
curl_setopt($ch, CURLOPT_COOKIESESSION, 1); //forza l'uso di cookie nuovi
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); //per salvare i cookie

$result = curl_exec($ch);
$errors=curl_error($ch);
curl_close($ch);



echo '<br>Result:<br>';
echo $result;
echo'<br>------------------<br>Errors:<br>';
echo $errors; 
echo'<br>------------------<br>Cookies:<br>';
echo file_get_contents($cookie);

?>

This page doesn't work.

<?php

$url = 'https://www.portaleargo.it/argoweb/famiglia/common/j_security_check';

$cookie = __DIR__ . '/cookie.txt'; // file and folder must be writeable

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'utente=xxxxxxx&j_password=xxxxxxx&j_username=xxxxxxx#SS16589&submit=Entra');

/*
//tried in another way, same result
$data = array(
    'utente' => 'xxxxxxx',
    'j_password' => 'xxxxxxx',
    'j_username' => 'xxxxxxx#SS16589',
    'submit' => 'Entra'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
*/

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1000); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);

curl_setopt($ch, CURLOPT_CAINFO, getcwd().'\cacert.pem');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //per usare i cookie


$result = curl_exec($ch);
$errors=curl_error($ch);
curl_close($ch);



echo '<br>Result:<br>';
echo $result;
echo'<br>------------------<br>Errors:<br>';
echo $errors; 
echo'<br>------------------<br>Cookies:<br>';
echo file_get_contents($cookie);
?>

At first i sent the # char like in the prompt request ("%"23) but the site didn't recognised it, so i changed and it seem to work.

EDIT: the "#" char is ok, the " in the "%"23 were wrong. Putting just %23 works (but still have the same error).

But now i have this error from the result of the second php page:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NullPointerException
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:154)
    com.backbase.bjsf.webapp.filter.UploadFilter.doFilter(Unknown Source)
    com.backbase.bjsf.webapp.filter.BackbaseApplicationFilter.doFilter(Unknown Source)
    it.argosoft.alunniweb.modulofamiglia.filter.ModuloFamigliaUserFilter.doFilter(ModuloFamigliaUserFilter.java:97)
root cause

javax.faces.FacesException: java.lang.NullPointerException
    org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:425)
    org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
    com.backbase.bjsf.application.BackbaseViewHandler.renderView(Unknown Source)
    org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
    org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
    com.backbase.bjsf.webapp.filter.UploadFilter.doFilter(Unknown Source)
    com.backbase.bjsf.webapp.filter.BackbaseApplicationFilter.doFilter(Unknown Source)
    it.argosoft.alunniweb.modulofamiglia.filter.ModuloFamigliaUserFilter.doFilter(ModuloFamigliaUserFilter.java:97)
root cause

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:413)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
    org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
    com.backbase.bjsf.application.BackbaseViewHandler.renderView(Unknown Source)
    org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
    org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
    com.backbase.bjsf.webapp.filter.UploadFilter.doFilter(Unknown Source)
    com.backbase.bjsf.webapp.filter.BackbaseApplicationFilter.doFilter(Unknown Source)
    it.argosoft.alunniweb.modulofamiglia.filter.ModuloFamigliaUserFilter.doFilter(ModuloFamigliaUserFilter.java:97)
root cause

java.lang.NullPointerException
    com.backbase.bjsf.component.UIBBComponentBase.initProperties(Unknown Source)
    com.backbase.bjsf.component.UIBackbaseComponentBase.initProperties(Unknown Source)
    com.backbase.bjsf.component.UIBackbaseCommandButton.initProperties(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.c(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.saveSerializedView(Unknown Source)
    org.apache.myfaces.taglib.core.ViewTag.doAfterBody(ViewTag.java:125)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:585)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
    org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
    com.backbase.bjsf.application.BackbaseViewHandler.renderView(Unknown Source)
    org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
    org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
    com.backbase.bjsf.webapp.filter.UploadFilter.doFilter(Unknown Source)
    com.backbase.bjsf.webapp.filter.BackbaseApplicationFilter.doFilter(Unknown Source)
    it.argosoft.alunniweb.modulofamiglia.filter.ModuloFamigliaUserFilter.doFilter(ModuloFamigliaUserFilter.java:97)
note The full stack trace of the root cause is available in the JBoss Web/7.0.17.Final logs.

Which are the differences between the two requests (prompt and php)?

What can i do to solve this problem?

Any ideas?

Thanks for helping, and sorry for my orrible english. Giosch

  • 写回答

1条回答 默认 最新

  • dqeonr8554 2014-11-23 21:22
    关注

    I forgot to add the user agent to the two php Pages. I just deleted the comment option from the two script. This solved my problem

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 logisim中设计一个位于十字路口的交通信号灯控制系统
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e
  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度
  • ¥15 寻找一块做为智能割草机的驱动板(标签-stm32|关键词-m3)
  • ¥15 信息管理系统的查找和排序
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),怎么用读取的电磁传感器信号表示小车所在的位置
  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。
  • ¥15 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码