本地url访问
❶ 如何访问本地webservice的url代表的意义
一、WebService在cs后台程序中的调用 A、通过命名空间和类名直接调用 示例: WebService ws = new WebService(); string s = ws.HelloWorld(); B、通过添加WEB引用的方式调用,首先添加WEB引用,通过URL指向WEBSERVICE, 指定WEB引用名,假设为K...
❷ php怎样不使用框架的情况下本地模拟url路由,实现localhost/a/id/1这种的访问方式
要实现路由的话你依然需要框架中路由器的支持,因为服务器不能理解你路径的具体含义.所以你需要一个路由器来帮助服务器去处理特定的信息.
不想用现成的就自己写一个简单的,如下:
首先你需要在htdoc下放一个.htaccess来实现单文件入口:
<IfMolemod_rewrite.c>
RewriteEngineOn
RewriteRule^$index.php?_url=[QSA,PT,L]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule^(.*)$index.php?_url=$1[QSA,L]
</IfMole>
然后自己写路由咯, index.php
<?php
//这里添加你想要的路径
$route=array(
//(:num)表示匹配任何数字,(:any)表示任意字符
'a/id/(:num)'=>'TestController:idAction',
'a/any/(:any)'=>'TestController:anyAction',
'a/no' =>'TestController:noAction',
//这里是默认控制器,就是当你访问localhost的时候用
'_DEFAULT_'=>'IndexController:indexAction',
);
//简单的Router
classRouter
{
private$route;
publicfunction__construct(array$route)
{
$this->route=$route;
}
publicfunctionparse($url)
{
if(empty($url)){
list($controller,$action)=explode(':',$this->route['_DEFAULT_']);
returnarray(
'controller'=>$controller,
'action' =>$action,
'params' =>array(),
);
}
$trans=array(
':any'=>'[^/]+',
':num'=>'[0-9]+'
);
foreach($this->routeas$u=>$d){
$pattern='#^'.strtr($u,$trans).'$#';
if(preg_match($pattern,$url,$params)){
list($controller,$action)=explode(':',$d);
array_shift($params);
returnarray(
'controller'=>$controller,
'action' =>$action,
'params' =>$params,
);
}
}
header("HTTP/1.0404NotFound");
exit('Pagenotfound');
}
}
$r=newRouter($route);
$arr=$r->parse($_GET['_url']);
require($arr['controller'].'.php');
//执行控制器的功能
$dispatcher=new$arr['controller'];
call_user_func_array(array($dispatcher,$arr['action']),$arr['params']);
?>
控制器1. Testcontroller.php
<?php
classTestController
{
publicfunctionidAction($id)
{
echo"Yourint-onlyidis:{$id}";
}
publicfunctionanyAction($any_id)
{
echo"Youanyidis:{$any_id}";
}
publicfunctionnoAction()
{
echo"Thismethodtakenoparameter";
}
}
默认控制器: IndexController.php
<?php
classIndexController
{
publicfunctionindexAction()
{
echo"HelloWorld!";
}
}
把.htaccess, index.php, TestController.php, IndexController.php放在htdoc里就可以了
❸ 如何用okhttp访问本地url
POST TO A SERVER
Posting a String:
public static final MediaType jsonReq
= MediaType.parse(application/json; charset=utf-8);
OkHttpClient client = new OkHttpClient();
String post(String url, String json) throws IOException {
RequestBody body = RequestBody.create(jsonReq, json);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
Posting Streaming:
public static final MediaType MEDIA_TYPE_MARKDOWN
= MediaType.parse(text/x-markdown; charset=utf-8);
private final OkHttpClient client = new OkHttpClient();
public void run() throws Exception {
RequestBody requestBody = new RequestBody() {
@Override public MediaType contentType() {
return MEDIA_TYPE_MARKDOWN;
}
@Override public void writeTo(BufferedSink sink) throws IOException {
sink.writeUtf8(Numbers
);
sink.writeUtf8(-------
);
for (int i = 2; i <= 997; i++) {
sink.writeUtf8(String.format( * %s = %s
, i, factor(i)));
}
}
private String factor(int n) {
for (int i = 2; i < n; i++) {
int x = n / i;
if (x * i == n) return factor(x) + × + i;
}
return Integer.toString(n);
}
};
Request request = new Request.Builder()
.url()
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException(Unexpected code + response);
System.out.println(response.body().string());
}
Posting a File:
public static final MediaType MEDIA_TYPE_MARKDOWN
= MediaType.parse(text/x-markdown; charset=utf-8);
private final OkHttpClient client = new OkHttpClient();
public void run() throws Exception {
File file = new File(README.md);
Request request = new Request.Builder()
.url()
.post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file))
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException(Unexpected code + response);
System.out.println(response.body().string());
}
Posting from parameters:
private final OkHttpClient client = new OkHttpClient();
public void run() throws Exception {
RequestBody formBody = new FormEncodingBuilder()
.add(search, Jurassic Park)
.build();
Request request = new Request.Builder()
.url()
.post(formBody)
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException(Unexpected code + response);
System.out.println(response.body().string());
}
Posting a multipart request:
private static final String IMGUR_CLIENT_ID = ...;
private static final MediaType MEDIA_TYPE_PNG = MediaType.parse(image/png);
private final OkHttpClient client = new OkHttpClient();
public void run() throws Exception {
// Use the imgur image upload API as documented at
RequestBody requestBody = new MultipartBuilder()
.type(MultipartBuilder.FORM)
.addPart(
Headers.of(Content-Disposition, form-data; name= itle),
RequestBody.create(null, Square Logo))
.addPart(
Headers.of(Content-Disposition, form-data; name=image),
RequestBody.create(MEDIA_TYPE_PNG, new File(website/static/logo-square.png)))
.build();
Request request = new Request.Builder()
.header(Authorization, Client-ID + IMGUR_CLIENT_ID)
.url()
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException(Unexpected code + response);
System.out.println(response.body().string());
}
Posing Json with Gson
private final OkHttpClient client = new OkHttpClient();
private final Gson gson = new Gson();
public void run() throws Exception {
Request request = new Request.Builder()
.url()
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException(Unexpected code + response);
Gist gist = gson.fromJson(response.body().charStream(), Gist.class);
for (Map.Entry entry : gist.files.entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue().content);
}
}
static class Gist {
Map files;
}
static class GistFile {
String content;
}
Response Caching:
为了缓存响应,你需要一个你可以读写的缓存目录,和缓存大小的限制。这个缓存目录应该是私有的,不信任的程序应不能读取缓存内容。
一个缓存目录同时拥有多个缓存访问是错误的。大多数程序只需要调用一次 new OkHttp() ,在第一次调用时配置好缓存,然后其他地方只需要调用这个实例就可以了。否则两个缓存示例互相干扰,破坏响应缓存,而且有可能会导致程序崩溃。
响应缓存使用HTTP头作为配置。你可以在请求头中添加 Cache-Control: max-stale=3600 ,OkHttp缓存会支持。你的服务通过响应头确定响应缓存多长时间,例如使用 Cache-Control: max-age=9600 。
❹ java项目怎么把本地图片改为别人可以访问的url路径
项目放在服务器上,上传的时候使用绝对路径上传到项目所在的文件夹下,把路径进行处理,数据库中存放的是服务器的域名或者ip加上图片在项目中的路径,数据库中怎么会存放本地路径呢?
❺ 在本地访问自己网站URL的问题
与HOSTS有一定的关系
可以作成http://我站点的名字
❻ 本地网页的url是什么
装本地套件,phpfind,iis之类的,完后把网页扔到对应文件夹,url的话就是127.0.0.1/xxxxx
❼ url是指网络路径,那本地路径怎么表示啊
本地路径是访问本机的磁盘文件,以file://开头
URL网络路径是以http://开头
比如这个就是本地路径
file:///D|/我的文档/localweb/oa/images/0-1.jpg
❽ 您访问的url有可能对网站造成威胁怎么解决
摘要 您好,这属于web应用防火墙的问题,假设防火墙检测到访问的URL存在安全漏洞或者注入等行为(简单来讲可能是攻击),会根据规矩集合对访问实现阻止或告警,这个可以通过黑白名单控制。也可能由于云盾的应用防火墙对URL访问判定存在攻击行为,从而进行了安全拦截。用户可以将自己的本地公网IP,添加到云盾应用防火墙的白名单中,这样就可以避免在正常测试访问中遭遇安全拦截。具体的操作步骤,详情请参考KB文档。