我正在尝试创建一个显示网页的JPanel.我已经到了可以阅读网页的阶段,但是当我显示页面时,它看起来很混乱,见下文.

这是源代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
public class Browser {
private JFrame frame;
private JPanel panelTop;
private JEditorPane editor;
private JScrollPane scroll;
private JTextField field;
private JButton button;
private URL url;
public Browser(String title) {
initComponents();
//set the title of the frame
frame.setTitle(title);
//set the default cloe op of the jframe
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//set size of frame
frame.setSize(800,600);
//add jpanel to north of jframe
frame.add(BorderLayout.NORTH, panelTop);
//add textfield and navigation button to jpanel.
panelTop.add(field);
panelTop.add(button); …Run Code Online (Sandbox Code Playgroud) 我通过HTTP POST将一些参数传递给网络服务器.
我得到了一个响应,但理想情况下我想要一个完整的XML响应,而我似乎只得到一个连接的字符串.我已经尝试过SimpleXMLElement,但它似乎没有做任何事情,并且它没有返回任何XML.
以下是我的代码:
$post_string = '<?xml version="1.0" encoding="utf-16" ?>
<ChameleonIAPI>
<Method>TitleList</Method>
<APIKey>D12E9CF3-F742-47FC-97CB-295F4488C2FA</APIKey>
<UserName>David</UserName>
<Filter>
</Filter>
</ChameleonIAPI>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://jobs.chameleoni.com/PostXML/PostXml.aspx");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"Action=postxml&AuthKey=Guest&AuthPassword=KgwLLm7TL6G6&Xml=$post_string");
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
$server_output = curl_exec ($ch);
echo $server_output." TEST <br />";
curl_close ($ch);
$oXML = new SimpleXMLElement($server_output);
foreach($oXML->entry as $oEntry){
echo $oEntry->title . "\n";
}
Run Code Online (Sandbox Code Playgroud)
这是您甚至可以测试POST和XML的页面.
https://jobs.chameleoni.com/PostXML/PostingXML.html
我的XML似乎没问题,因为它适用于测试页面.我认为我的PHP有问题,虽然我不知道那是什么!
任何帮助都很可爱!