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

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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。