简体   繁体   English

cURL-提示脚本有效,但curl-php的相同请求无效(内部服务器错误500)

[英]cURL - prompt script works while same request with curl-php doesn't (Internal server error 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. 我尝试从提示中使用cUrl,并设法分两个步骤进行操作:首先,我将获取请求发送到页面以保存cookie,然后使用这些cookie将发布请求发送到另一个登录页面。页。

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. 我需要开发一个可以执行相同任务的php页面。

This first page works . 此首页有效 I get my cookie.txt full of delicious cookies. 我的cookie.txt充满了美味的饼干。

<?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. 最初,我像在提示请求中一样发送了#字符(“%” 23),但该站点无法识别它,因此我进行了更改,它似乎可以正常工作。

EDIT : the "#" char is ok, the " in the "%"23 were wrong. Putting just %23 works (but still have the same error). 编辑“#”字符是可以的,“%” 23中的“是错误的。仅将%23放入即可(但仍然有相同的错误)。

But now i have this error from the result of the second php page : 但是现在我从第二个php页面的结果中得到了这个错误

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 )? 两个请求提示符php之间有什么区别

What can i do to solve this problem? 我该怎么做才能解决这个问题?

Any ideas? 有任何想法吗?

Thanks for helping, and sorry for my orrible english. 感谢您的帮助,对不起我的英语不好。 Giosch 乔施

I forgot to add the user agent to the two php Pages. 我忘记将用户代理添加到两个php页面中。 I just deleted the comment option from the two script. 我只是从两个脚本中删除了注释选项。 This solved my problem 这解决了我的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM